Comprehensive PowerShell toolkit for IT security auditing, user account analysis, and compliance reporting
- Overview
- System Requirements
- Installation
- Quick Start
- Features
- Step-by-Step Usage Guide
- Command Reference
- Export Formats
- Compliance Frameworks
- Real-World Examples
- Troubleshooting
- Advanced Topics
ITAuditKit is a professional-grade PowerShell toolkit designed for IT administrators, security auditors, and compliance officers. It provides comprehensive user account auditing, security risk assessment, and compliance reporting across multiple platforms.
β Multi-Source Data Collection
- Microsoft Entra ID (Azure AD) - Cloud identities
- Active Directory - On-premises identities
- Local Windows accounts - Workstation/server accounts
β Security Analysis
- MFA status and enforcement
- Privileged account identification
- Password policy compliance
- Account lockout risks
- Security risk scoring (color-coded)
- Windows Hello for Business (WHfB) status
β Compliance Reporting
- 7 major frameworks supported: SOX, HIPAA, GDPR, PCI-DSS, ISO27001, NIST, CIS
- Pass/Fail status with detailed metrics
- Automated compliance assessment
β Advanced Filtering
- Filter by department, location, job title
- Filter by MFA status, risk level, account status
- Filter by login activity and date ranges
- Target specific user populations
β Multiple Export Formats
- Excel (recommended) - Multiple worksheets with formatting
- CSV - Data analysis friendly
- JSON - Automation and API integration
- HTML - Professional reports for stakeholders
- XML - PowerShell native format
β Performance Features
- Caching system for faster repeated queries
- Configurable cache expiry
- Progress indicators
- Summary statistics
- PowerShell 7.0 or higher
β οΈ IMPORTANT- PowerShell 5.1 is NOT supported
- The script will automatically check and prompt if needed
- Download: PowerShell 7+
| Data Source | Required Permissions |
|---|---|
| Entra ID | Global Reader, User Administrator, or similar role with user read permissions |
| Active Directory | Domain user with read access to AD |
| Local Accounts | Local Administrator rights on the target machine |
# For Excel export functionality (highly recommended)
Install-Module ImportExcel -Scope CurrentUser
# For Entra ID (Azure AD) access
Install-Module Microsoft.Graph -Scope CurrentUser# Clone the repository
git clone https://github.com/yourusername/ITAuditKit.git
cd ITAuditKit
# Or download and extract the ZIP file# Check your PowerShell version
$PSVersionTable.PSVersion
# Should show: Major 7 or higher
# If not, download PowerShell 7+ from:
# https://github.com/PowerShell/PowerShell/releases# For Excel export (recommended)
Install-Module ImportExcel -Scope CurrentUser -Force
# For Microsoft Entra ID access
Install-Module Microsoft.Graph -Scope CurrentUser -Force# Allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser# Navigate to the toolkit directory
cd C:\Path\To\ITAuditKit
# Run a basic test
.\users\users.ps1 -IncludeLocal -ListUsers -MaxRecords 5.\users\users.ps1 -IncludeEntraID -ListUsersWhat it does: Connects to Microsoft Graph, retrieves all cloud users, displays in console
.\users\users.ps1 -IncludeLocal -ListUsersWhat it does: Lists all local accounts on the current machine
.\users\users.ps1 -IncludeAD -ListUsersWhat it does: Queries your on-premises Active Directory for user accounts
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\MyReport.xlsx"What it does: Creates an Excel file with all user data
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "SOX" -ExportExcel -ExcelPath ".\SOX_Audit.xlsx"What it does: Creates compliance report with Excel export
.\users\users.ps1 -IncludeEntraID -ListUsers -OutputDirectory "C:\Reports\SecurityAudits" -ExportExcel -ExcelPath "Audit.xlsx" -IncludeExportFormatsWhat it does: Creates all export files in the specified directory (creates folder if it doesn't exist)
The -OutputDirectory parameter helps you keep reports organized:
# Organize by date
.\users\users.ps1 -IncludeEntraID -ListUsers `
-OutputDirectory "C:\Reports\$(Get-Date -Format 'yyyy-MM')" `
-ExportExcel -ExcelPath "SecurityAudit.xlsx"
# Organize by department
.\users\users.ps1 -IncludeEntraID -ListUsers `
-FilterByDepartment "IT" `
-OutputDirectory "C:\Reports\Departments\IT" `
-ExportExcel -ExcelPath "IT_Audit.xlsx"
# Organize by compliance framework
.\users\users.ps1 -IncludeEntraID -ListUsers `
-ComplianceFramework "SOX" `
-OutputDirectory "C:\ComplianceReports\SOX\2025" `
-ExportExcel -ExcelPath "SOX_Q1_2025.xlsx" `
-IncludeExportFormatsBenefits:
- β Automatic folder creation if it doesn't exist
- β All exports (Excel, CSV, JSON, HTML, XML) go to the same directory
- β Easy to organize by date, department, or compliance framework
- β Simplifies report archival and sharing
- β Works with relative and absolute paths
Retrieves cloud identity information including:
- User principal name, display name, email
- MFA status and authentication methods
- Sign-in activity and last login
- Account enabled/disabled status
- Assigned roles and group memberships
- Department, job title, office location
- Guest user identification
Retrieves on-premises directory information including:
- SAM account name, user principal name
- Account status (enabled/disabled/locked)
- Password last set, password expiry
- Last logon timestamp
- Group memberships
- Organizational unit (OU)
- Account creation date
Retrieves local machine account information including:
- Local usernames
- Account status
- Login history from event logs
- Last interactive logon
- Account creation date
- Administrative rights
The script automatically calculates security risk scores based on:
-
MFA Status (30% weight)
- No MFA = High risk
- Partial MFA = Medium risk
- Full MFA = Low risk
-
Password Policy (25% weight)
- Never expires = High risk
- Old passwords = Medium risk
- Strong policies = Low risk
-
Account Activity (20% weight)
- Inactive accounts = High risk
- Stale accounts = Medium risk
- Active accounts = Low risk
-
Privileged Access (25% weight)
- Privileged without MFA = Critical risk
- Privileged with MFA = Monitored
Risk Levels:
- π΄ Critical (90-100) - Immediate action required
- π High (70-89) - Urgent attention needed
- π‘ Medium (40-69) - Should be addressed
- π’ Low (20-39) - Minor concerns
- βͺ Minimal (0-19) - Good security posture
-FilterByDepartment "IT" # Filter by department
-FilterByLocation "New York" # Filter by office location
-FilterByJobTitle "Manager" # Filter by job title-ShowOnlyNoMFA # Only users without MFA
-ShowOnlyPrivileged # Only admin/privileged accounts
-ShowOnlyDisabled # Only disabled accounts
-ShowOnlyGuests # Only guest/external users
-FilterByRiskLevel "Critical" # By risk level-InactiveDays 90 # Inactive for 90+ days
-LastLoginAfter "2024-01-01" # Logged in after date
-LastLoginBefore "2024-12-31" # Logged in before dateSpeed up repeated queries with intelligent caching:
# First run: fetches fresh data (takes ~10 seconds)
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache
# Second run: uses cached data (takes ~2 seconds)
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "IT"
# Control cache expiry
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -CacheExpiryMinutes 30
# Clear cache when you need fresh data
.\users\users.ps1 -ClearCacheCache Benefits:
- 70% faster on repeated queries
- Reduces API calls to Microsoft Graph
- Ideal for running multiple filtered reports
- Automatic expiry ensures data freshness
Generate automated compliance reports for major frameworks:
| Framework | Full Name | Focus Areas |
|---|---|---|
| SOX | Sarbanes-Oxley Act | Financial data integrity, access controls, segregation of duties |
| HIPAA | Health Insurance Portability and Accountability Act | Protected Health Information (PHI) access controls |
| GDPR | General Data Protection Regulation | Data subject rights, access control, data minimization |
| PCI-DSS | Payment Card Industry Data Security Standard | Cardholder data protection, strong access control |
| ISO27001 | Information Security Management | Access control, user management, authentication |
| NIST | NIST Cybersecurity Framework | Identify, Protect, Detect, Respond, Recover |
| CIS | CIS Controls v8 | Critical security controls, account management |
Each report includes:
- β /β Pass/Fail status
- Detailed metrics and counts
- Control point mapping
- Specific findings
- Risk indicators
- Actionable recommendations
Goal: Get a list of all users in your organization
Steps:
- Open PowerShell 7
- Navigate to ITAuditKit folder
- Run the appropriate command for your environment:
# For Microsoft 365 / Entra ID
.\users\users.ps1 -IncludeEntraID -ListUsers
# For Active Directory
.\users\users.ps1 -IncludeAD -ListUsers
# For both cloud and on-premises
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers- Review the console output
- Look for the summary statistics at the bottom
Goal: Identify high-risk accounts that need immediate attention
Steps:
- Run with risk scoring enabled:
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore- Filter for critical/high risk only:
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "Critical"- Export findings to Excel:
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "Critical" -ExportExcel -ExcelPath ".\HighRisk_Users.xlsx"- Open the Excel file and review the "Risk Score" column
- Color coding helps identify critical issues quickly
Goal: Find all users without MFA enabled
Steps:
- Identify users without MFA:
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA- Export for remediation:
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA -ExportExcel -ExcelPath ".\Users_NoMFA.xlsx"- Focus on privileged accounts first:
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA -ShowOnlyPrivileged -ExportExcel -ExcelPath ".\Privileged_NoMFA_URGENT.xlsx"- Share the Excel file with your security team
- Track remediation progress
Goal: Find and disable accounts that haven't been used in 90 days
Steps:
- Find inactive accounts:
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 90- Export the list:
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 90 -ExportExcel -ExcelPath ".\Inactive_90days.xlsx"- Review the Excel file with management
- Get approval for account disabling
- Use the list to disable/delete accounts in your directory
Goal: Audit all IT department users
Steps:
- List IT department users:
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "IT"- Check for security issues:
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "IT" -ShowOnlyNoMFA- Generate comprehensive report:
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "IT" -IncludeRiskScore -IncludeMFADetails -IncludeGroups -ExportExcel -ExcelPath ".\IT_Department_Audit.xlsx"- Review with IT management
- Track any required changes
Goal: Generate SOX compliance report for annual audit
Steps:
- Generate SOX report with all data:
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -ComplianceFramework "SOX" -ExportExcel -ExcelPath ".\SOX_Audit_2025.xlsx" -IncludeExportFormats-
This creates:
- Excel file with user data + compliance worksheet
- CSV files for data analysis
- JSON file for automation
- HTML report for presentation
- XML for archival
-
Review the compliance worksheet in Excel
-
Address any "NON-COMPLIANT" or "FAIL" items
-
Re-run after remediation to verify compliance
Goal: Run multiple filtered reports quickly
Steps:
- First query with cache enabled:
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache- Now run multiple filters (all use cached data):
# IT department
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "IT"
# Finance department
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "Finance"
# Privileged accounts
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -ShowOnlyPrivileged
# No MFA
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -ShowOnlyNoMFA- All queries run 70% faster using cached data
- Cache expires after 60 minutes (default)
- Use
-ClearCachewhen you need fresh data
Goal: Generate compliance reports for all frameworks
Steps:
- Run comprehensive compliance check:
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -ComplianceFramework "All" -ExportExcel -ExcelPath ".\Full_Compliance_2025.xlsx" -IncludeExportFormats-
This generates reports for all 7 frameworks:
- SOX (Financial)
- HIPAA (Healthcare)
- GDPR (Privacy)
- PCI-DSS (Payment cards)
- ISO27001 (Information security)
- NIST (Cybersecurity)
- CIS (Critical controls)
-
Review each framework's status
-
Create remediation plan for any failures
-
Track progress over time
| Parameter | Description | Example |
|---|---|---|
-IncludeEntraID |
Include Entra ID (Azure AD) users | -IncludeEntraID |
-IncludeAD |
Include Active Directory users | -IncludeAD |
-IncludeLocal |
Include local machine users | -IncludeLocal |
-ListUsers |
Display user list format | -ListUsers |
-MaxRecords <int> |
Limit number of records per source | -MaxRecords 100 |
-Minimal |
Show minimal output (fewer columns) | -Minimal |
-OutGridView |
Display in interactive grid | -OutGridView |
| Parameter | Description | Example |
|---|---|---|
-FilterByDepartment <string> |
Filter by department | -FilterByDepartment "IT" |
-FilterByLocation <string> |
Filter by location | -FilterByLocation "London" |
-FilterByJobTitle <string> |
Filter by job title | -FilterByJobTitle "Manager" |
-FilterByRiskLevel <string> |
Filter by risk level | -FilterByRiskLevel "Critical" |
-ShowOnlyNoMFA |
Show only users without MFA | -ShowOnlyNoMFA |
-ShowOnlyPrivileged |
Show only privileged accounts | -ShowOnlyPrivileged |
-ShowOnlyDisabled |
Show only disabled accounts | -ShowOnlyDisabled |
-ShowOnlyGuests |
Show only guest users | -ShowOnlyGuests |
-InactiveDays <int> |
Show inactive users (X days) | -InactiveDays 90 |
-LastLoginAfter <datetime> |
Logins after date | -LastLoginAfter "2024-01-01" |
-LastLoginBefore <datetime> |
Logins before date | -LastLoginBefore "2024-12-31" |
| Parameter | Description | Example |
|---|---|---|
-IncludeRiskScore |
Calculate security risk scores | -IncludeRiskScore |
-IncludeMFADetails |
Include MFA method details | -IncludeMFADetails |
-IncludeGroups |
Include group memberships | -IncludeGroups |
-IncludePIN |
Include WHfB PIN status | -IncludePIN |
-IncludePasswordPolicy |
Include password policy analysis | -IncludePasswordPolicy |
-IncludeLockoutStatus |
Include account lockout info | -IncludeLockoutStatus |
-IncludeAppPermissions |
Include app permissions | -IncludeAppPermissions |
| Parameter | Description | Example |
|---|---|---|
-ExportExcel |
Enable Excel export | -ExportExcel |
-ExcelPath <string> |
Excel file path (default: Users_List.xlsx) | -ExcelPath ".\Report.xlsx" |
-ExcelWorksheet <string> |
Worksheet name (default: Users) | -ExcelWorksheet "Users" |
-OutputDirectory <string> |
Output directory for all exported files (default: current directory) | -OutputDirectory "C:\Reports" |
-IncludeExportFormats |
Export to all formats (CSV, JSON, HTML, XML) | -IncludeExportFormats |
| Parameter | Description | Example |
|---|---|---|
-ComplianceFramework <string[]> |
Generate compliance report | -ComplianceFramework "SOX" |
| Available: SOX, HIPAA, GDPR, PCI-DSS, ISO27001, NIST, CIS, All | -ComplianceFramework "All" |
| Parameter | Description | Example |
|---|---|---|
-UseCache |
Use cached data if available | -UseCache |
-CacheExpiryMinutes <int> |
Cache expiry (default: 60) | -CacheExpiryMinutes 30 |
-ClearCache |
Clear cache before running | -ClearCache |
Best for: Comprehensive reports, sharing with stakeholders, data analysis
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx"Features:
- Multiple worksheets (Users + Compliance)
- Professional table formatting
- Auto-sized columns
- Frozen headers
- Color-coded risk levels
- Easy to filter and sort
Compliance Integration:
- Separate "Compliance" worksheet
- All frameworks in one workbook
- Clear PASS/FAIL indicators
Best for: Data analysis in Excel/Python/R, importing to other systems
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx" -IncludeExportFormatsCreates:
Users_List_YYYYMMDD_HHMMSS.csv- User dataUsers_List_Compliance_YYYYMMDD_HHMMSS.csv- Compliance data (separate file)
Features:
- Universal compatibility
- Easy to import/parse
- Works with any data analysis tool
- UTF-8 encoding
Best for: Automation, API integration, custom dashboards
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx" -IncludeExportFormatsStructure:
{
"UserData": [...],
"ComplianceReports": [...],
"GeneratedAt": "2025-10-16T00:00:00",
"TotalUsers": 150
}Use Cases:
- Feed data to monitoring tools
- Custom PowerBI dashboards
- Automated workflows
- Integration with SIEM systems
Best for: Presentations, executive reports, sharing via email/web
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx" -IncludeExportFormatsFeatures:
- Professional styling
- Color-coded risk levels
- Compliance section with PASS/FAIL colors
- Printable format
- No software required to view
Perfect for:
- Board presentations
- Non-technical stakeholders
- Quick email reports
- Publishing to intranet
Best for: PowerShell workflows, archival, regulatory compliance
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx" -IncludeExportFormatsFeatures:
- PowerShell native format
- Can be re-imported with
Import-Clixml - Preserves object types
- Deep serialization
- Audit trail friendly
# Monday morning security check - saves to dedicated reports folder
.\users\users.ps1 -IncludeEntraID -ListUsers `
-IncludeRiskScore `
-FilterByRiskLevel "Critical" `
-OutputDirectory "C:\SecurityReports" `
-ExportExcel -ExcelPath "Weekly_Security_$(Get-Date -Format 'yyyy-MM-dd').xlsx"Use Case: Weekly review of critical security issues
Time: ~15 seconds
Output: Excel file with high-risk accounts in C:\SecurityReports folder
# Comprehensive pre-audit assessment - organized in audit folder
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-ComplianceFramework "All" `
-IncludeRiskScore `
-IncludeMFADetails `
-IncludeGroups `
-OutputDirectory "C:\AuditReports\2025" `
-ExportExcel -ExcelPath "Pre-Audit_Assessment_$(Get-Date -Format 'yyyy-MM-dd').xlsx" `
-IncludeExportFormatsUse Case: Annual audit preparation
Time: ~45 seconds
Output: Complete audit package (Excel, CSV, JSON, HTML, XML) in C:\AuditReports\2025
# Finance department monthly review
.\users\users.ps1 -IncludeEntraID -ListUsers `
-FilterByDepartment "Finance" `
-IncludeRiskScore `
-IncludeMFADetails `
-ComplianceFramework "SOX","PCI-DSS" `
-ExportExcel -ExcelPath ".\Finance_Security_Report_$(Get-Date -Format 'yyyy-MM').xlsx"Use Case: Monthly departmental security review
Time: ~10 seconds
Output: Excel with Finance users + SOX/PCI-DSS compliance
# Quarterly privileged account review
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-ShowOnlyPrivileged `
-IncludeRiskScore `
-IncludeMFADetails `
-IncludeGroups `
-IncludePasswordPolicy `
-ComplianceFramework "SOX","ISO27001","CIS" `
-ExportExcel -ExcelPath ".\Privileged_Accounts_Q$(Get-Date -Format 'MM')_2025.xlsx" `
-IncludeExportFormatsUse Case: Quarterly privileged access review
Time: ~20 seconds
Output: Complete privileged account assessment
# Find accounts inactive for 90+ days
.\users\users.ps1 -IncludeEntraID -ListUsers `
-InactiveDays 90 `
-ExportExcel -ExcelPath ".\Inactive_Accounts_Cleanup_$(Get-Date -Format 'yyyy-MM-dd').xlsx"
# Focus on non-privileged accounts first
.\users\users.ps1 -IncludeEntraID -ListUsers `
-InactiveDays 90 `
-ShowOnlyDisabled:$false `
-ExportExcel -ExcelPath ".\Inactive_Enabled_Accounts.xlsx"Use Case: Account hygiene and cleanup
Time: ~10 seconds
Output: List of accounts to review for disabling
# Quarterly external user access review
.\users\users.ps1 -IncludeEntraID -ListUsers `
-ShowOnlyGuests `
-IncludeRiskScore `
-IncludeMFADetails `
-ComplianceFramework "GDPR","ISO27001" `
-ExportExcel -ExcelPath ".\Guest_User_Review_Q$(Get-Date -Format 'MM')_2025.xlsx"Use Case: External access governance
Time: ~15 seconds
Output: All guest users with compliance check
# Check accounts created in last 30 days
.\users\users.ps1 -IncludeEntraID -ListUsers `
-LastLoginAfter (Get-Date).AddDays(-30) `
-IncludeMFADetails `
-ExportExcel -ExcelPath ".\New_Hires_$(Get-Date -Format 'yyyy-MM').xlsx"Use Case: Verify new employee account setup
Time: ~10 seconds
Output: Recent accounts and their security posture
# Find users with password policy violations
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-IncludePasswordPolicy `
-IncludeRiskScore `
-ComplianceFramework "PCI-DSS","ISO27001" `
-ExportExcel -ExcelPath ".\Password_Policy_Review_$(Get-Date -Format 'yyyy-MM-dd').xlsx"Use Case: Password policy enforcement
Time: ~20 seconds
Output: Users with weak/old passwords
# Create scheduled task for daily monitoring
$Script = @"
.\users\users.ps1 -IncludeEntraID -ListUsers ``
-UseCache ``
-FilterByRiskLevel "Critical" ``
-ShowOnlyNoMFA ``
-OutputDirectory "C:\Reports\Daily" ``
-ExportExcel -ExcelPath "Security_`$(Get-Date -Format 'yyyy-MM-dd').xlsx"
# Email if critical issues found
`$reportPath = "C:\Reports\Daily\Security_`$(Get-Date -Format 'yyyy-MM-dd').xlsx"
`$report = Import-Excel `$reportPath
if (`$report.Count -gt 0) {
Send-MailMessage -To "[email protected]" ``
-Subject "ALERT: Critical Security Issues Detected" ``
-Body "`$(`$report.Count) critical issues found. See attached report." ``
-Attachments `$reportPath
}
"@
# Save and schedule
$Script | Out-File "C:\Scripts\DailySecurityCheck.ps1"Use Case: Automated daily security monitoring
Time: Runs automatically
Output: Daily Excel reports + email alerts
# Complete environment audit (cloud + on-prem + local)
.\users\users.ps1 -IncludeEntraID -IncludeAD -IncludeLocal -ListUsers `
-IncludeRiskScore `
-IncludeMFADetails `
-IncludeGroups `
-IncludePasswordPolicy `
-IncludeLockoutStatus `
-ComplianceFramework "All" `
-ExportExcel -ExcelPath ".\Complete_Environment_Audit_$(Get-Date -Format 'yyyy-MM-dd').xlsx" `
-IncludeExportFormats `
-UseCacheUse Case: Comprehensive security audit
Time: ~60 seconds (first run), ~20 seconds (cached)
Output: Complete audit package with all data sources and compliance
This section provides examples for EVERY available feature, not just the major ones.
# Find specific user across all sources
.\users\users.ps1 -IncludeEntraID -IncludeAD -IncludeLocal -UserName "john.doe"# Get only first 50 users (faster for testing)
.\users\users.ps1 -IncludeEntraID -ListUsers -MaxRecords 50# Query remote computer
.\users\users.ps1 -IncludeLocal -ListUsers -ComputerName "SERVER01"# Audit local accounts on this machine
.\users\users.ps1 -IncludeLocal -ListUsers# Audit on-premises AD users
.\users\users.ps1 -IncludeAD -ListUsers# Audit Microsoft 365 / Azure AD users
.\users\users.ps1 -IncludeEntraID -ListUsers# Comprehensive audit across all identity systems
.\users\users.ps1 -IncludeEntraID -IncludeAD -IncludeLocal -ListUsers# Show users instead of login events
.\users\users.ps1 -IncludeEntraID -ListUsers# Check WHfB PIN registration and last WHfB sign-in
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludePIN# Show only essential columns (User, Rights, MFA, Roles, Last Login)
.\users\users.ps1 -IncludeEntraID -ListUsers -Minimal# Display in sortable, filterable grid view
.\users\users.ps1 -IncludeEntraID -ListUsers -OutGridView# Export to Excel file
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath "Report.xlsx"# Specify worksheet name
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath "Report.xlsx" -ExcelWorksheet "EntraID_Users"# Save all exports to specific folder
.\users\users.ps1 -IncludeEntraID -ListUsers -OutputDirectory "C:\Reports\Monthly" -ExportExcel -ExcelPath "Users.xlsx"# Export to Excel, CSV, JSON, HTML, and XML
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath "Report.xlsx" -IncludeExportFormats# Calculate security risk scores for each user
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScoreWhat it shows: Risk level (Critical/High/Medium/Low/Minimal) with color coding
# Identify and flag privileged accounts
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -IncludePrivilegedAccountsWhat it shows: Admin rights, privileged roles, elevated permissions
# Detect non-interactive service accounts
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -IncludeServiceAccountsWhat it shows: Service accounts, application accounts, automated accounts
# Analyze external/guest users
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeGuestUsersWhat it shows: Guest status, access expiration, external domains
# Check password policy compliance
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -IncludePasswordPolicyWhat it shows: Password age, complexity, expiration, policy violations
# Analyze lockout events and failed logins
.\users\users.ps1 -IncludeLocal -IncludeAD -ListUsers -IncludeAccountLockoutWhat it shows: Lockout status, failed login attempts, lockout risks
# Check device compliance status
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeDeviceComplianceWhat it shows: Managed devices, compliance status, device trust
# Analyze Conditional Access policy impact
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeConditionalAccessWhat it shows: Applied policies, policy compliance, access restrictions
# Include risky sign-in detection
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskySigninsWhat it shows: Risk detections, risky sign-ins, threat indicators
# Analyze group memberships and nested groups
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -IncludeGroupMembershipWhat it shows: Group memberships, nested groups, role assignments
# Audit app permissions and consent grants
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeAppPermissionsWhat it shows: App permissions, consent grants, OAuth apps
# Show only IT department users
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "IT"
# Partial match works too
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "Information Technology"# Show only users in New York office
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByLocation "New York"
# Multiple locations - run separately and combine
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByLocation "London"# Show only managers
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByJobTitle "Manager"
# Show directors and above
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByJobTitle "Director"# Users who logged in after Jan 1, 2025
.\users\users.ps1 -IncludeEntraID -ListUsers -LastLoginAfter "2025-01-01"
# Users who logged in this week
.\users\users.ps1 -IncludeEntraID -ListUsers -LastLoginAfter (Get-Date).AddDays(-7)# Users who logged in before Jan 1, 2025
.\users\users.ps1 -IncludeEntraID -ListUsers -LastLoginBefore "2025-01-01"
# Users who haven't logged in recently
.\users\users.ps1 -IncludeEntraID -ListUsers -LastLoginBefore (Get-Date).AddDays(-30)# Critical risk users only
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "Critical"
# High risk users
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "High"
# Low risk users
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "Low"# Show only users WITHOUT MFA
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA
# Critical: Privileged accounts without MFA
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA -ShowOnlyPrivileged# Show only privileged/admin accounts
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -ShowOnlyPrivileged# Show only disabled accounts
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers -ShowOnlyDisabled# Show only guest/external users
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyGuests
# Guest users without MFA (security risk!)
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyGuests -ShowOnlyNoMFA# Users inactive for 30+ days
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 30
# Users inactive for 90+ days (common threshold)
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 90
# Users inactive for 180+ days (cleanup candidates)
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 180# First run: fetches fresh data and caches it
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache
# Second run: uses cached data (much faster!)
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "IT"# Cache expires after 30 minutes
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -CacheExpiryMinutes 30
# Cache expires after 2 hours (120 minutes)
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -CacheExpiryMinutes 120# Clear cache before running (force fresh data)
.\users\users.ps1 -IncludeEntraID -ListUsers -ClearCache# SOX compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "SOX"
# HIPAA compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "HIPAA"
# GDPR compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "GDPR"
# PCI-DSS compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "PCI-DSS"
# ISO 27001 compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "ISO27001"
# NIST Cybersecurity Framework report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "NIST"
# CIS Controls v8 report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "CIS"
# All frameworks at once
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "All"
# Multiple specific frameworks
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "SOX","HIPAA","PCI-DSS"# Show help information
.\users\users.ps1 -Help# Load settings from JSON config file
.\users\users.ps1 -ConfigFile "C:\Config\audit-config.json"# Quick profile (minimal data, fast)
.\users\users.ps1 -Profile Quick
# Comprehensive profile (all features)
.\users\users.ps1 -Profile Comprehensive
# Security profile (security-focused features)
.\users\users.ps1 -Profile Security# Everything security-related
.\users\users.ps1 -IncludeEntraID -IncludeAD -IncludeLocal -ListUsers `
-IncludeRiskScore `
-IncludePrivilegedAccounts `
-IncludeServiceAccounts `
-IncludeGuestUsers `
-IncludePasswordPolicy `
-IncludeAccountLockout `
-IncludeDeviceCompliance `
-IncludeConditionalAccess `
-IncludeRiskySignins `
-IncludeGroupMembership `
-IncludeAppPermissions `
-ExportExcel -ExcelPath "Complete_Security_Audit.xlsx" `
-IncludeExportFormats# Comprehensive privileged account analysis
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-ShowOnlyPrivileged `
-IncludeRiskScore `
-IncludePasswordPolicy `
-IncludeAccountLockout `
-IncludeGroupMembership `
-IncludeConditionalAccess `
-ComplianceFramework "SOX","ISO27001","CIS" `
-OutputDirectory "C:\PrivilegedAccounts\$(Get-Date -Format 'yyyy-MM-dd')" `
-ExportExcel -ExcelPath "Privileged_Accounts_Audit.xlsx" `
-IncludeExportFormats# Comprehensive guest user analysis
.\users\users.ps1 -IncludeEntraID -ListUsers `
-ShowOnlyGuests `
-IncludeRiskScore `
-IncludeGuestUsers `
-IncludeConditionalAccess `
-IncludeAppPermissions `
-ComplianceFramework "GDPR","ISO27001" `
-ExportExcel -ExcelPath "Guest_User_Review.xlsx"# IT department comprehensive audit
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-FilterByDepartment "IT" `
-IncludeRiskScore `
-IncludePrivilegedAccounts `
-IncludePasswordPolicy `
-IncludeAccountLockout `
-IncludeGroupMembership `
-ComplianceFramework "All" `
-OutputDirectory "C:\Reports\Departments\IT\$(Get-Date -Format 'yyyy-MM')" `
-ExportExcel -ExcelPath "IT_Department_Audit.xlsx" `
-IncludeExportFormats# Find all inactive accounts with full context
.\users\users.ps1 -IncludeEntraID -IncludeAD -IncludeLocal -ListUsers `
-InactiveDays 90 `
-IncludeRiskScore `
-IncludePasswordPolicy `
-IncludeGroupMembership `
-ShowOnlyDisabled:$false `
-OutputDirectory "C:\Cleanup\Inactive_$(Get-Date -Format 'yyyy-MM-dd')" `
-ExportExcel -ExcelPath "Inactive_Accounts.xlsx" `
-IncludeExportFormats# Find all users without MFA, prioritized by risk
.\users\users.ps1 -IncludeEntraID -ListUsers `
-ShowOnlyNoMFA `
-IncludeRiskScore `
-IncludePrivilegedAccounts `
-IncludeConditionalAccess `
-FilterByRiskLevel "Critical" `
-OutputDirectory "C:\MFA_Campaign\$(Get-Date -Format 'yyyy-MM-dd')" `
-ExportExcel -ExcelPath "NoMFA_Critical.xlsx"# Find all password policy violations
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-IncludePasswordPolicy `
-IncludeRiskScore `
-ComplianceFramework "PCI-DSS","ISO27001" `
-OutputDirectory "C:\PasswordAudit\$(Get-Date -Format 'yyyy-MM-dd')" `
-ExportExcel -ExcelPath "Password_Policy_Audit.xlsx"# First: Load data and cache it
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -CacheExpiryMinutes 120
# Then: Run multiple queries using cached data (very fast!)
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "Finance" -ExportExcel -ExcelPath "Finance.xlsx"
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment "IT" -ExportExcel -ExcelPath "IT.xlsx"
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -ShowOnlyPrivileged -ExportExcel -ExcelPath "Privileged.xlsx"
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -ShowOnlyNoMFA -ExportExcel -ExcelPath "NoMFA.xlsx"# Audit all users in specific location with full security context
.\users\users.ps1 -IncludeEntraID -ListUsers `
-FilterByLocation "London" `
-IncludeRiskScore `
-IncludeDeviceCompliance `
-IncludeConditionalAccess `
-ComplianceFramework "GDPR","ISO27001" `
-OutputDirectory "C:\Reports\Locations\London\$(Get-Date -Format 'yyyy-MM')" `
-ExportExcel -ExcelPath "London_Office_Audit.xlsx" `
-IncludeExportFormats# Users who logged in during Q1 2025
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-LastLoginAfter "2025-01-01" `
-LastLoginBefore "2025-03-31" `
-IncludeRiskScore `
-OutputDirectory "C:\Reports\Activity\2025-Q1" `
-ExportExcel -ExcelPath "Q1_Activity.xlsx"# Quick overview with minimal columns (fast!)
.\users\users.ps1 -IncludeEntraID -ListUsers `
-Minimal `
-MaxRecords 100 `
-OutGridView# Open in GUI for interactive filtering
.\users\users.ps1 -IncludeEntraID -ListUsers `
-IncludeRiskScore `
-IncludePrivilegedAccounts `
-IncludePasswordPolicy `
-IncludeGroupMembership `
-OutGridViewProblem: Script requires PowerShell 7+, you have 5.1 or older
Solution:
# Download and install PowerShell 7
# Visit: https://github.com/PowerShell/PowerShell/releases
# Or use winget
winget install Microsoft.PowerShell
# Verify installation
pwsh -VersionProblem: Excel export fails, falls back to CSV
Solution:
# Install the ImportExcel module
Install-Module ImportExcel -Scope CurrentUser -Force
# Verify installation
Get-Module -ListAvailable ImportExcelProblem: Entra ID queries fail with authentication error
Solution:
# Install Microsoft Graph module
Install-Module Microsoft.Graph -Scope CurrentUser -Force
# Try manual connection first
Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All"
# Then run the script
.\users\users.ps1 -IncludeEntraID -ListUsersProblem: Cannot query AD, permission denied
Solution:
- Ensure you're logged in with a domain account
- Verify you have "Read" permissions to Active Directory
- Run from a domain-joined machine
- Try specifying a different DC:
.\users\users.ps1 -IncludeAD -ListUsers -DomainController "DC01.domain.com"Problem: Excel file created but missing compliance data
Solution:
Ensure you specify -ComplianceFramework:
# Correct usage
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "SOX" -ExportExcel -ExcelPath ".\Report.xlsx"Problem: Takes too long to fetch data
Solutions:
# Use caching for repeated queries
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache
# Limit number of records
.\users\users.ps1 -IncludeEntraID -ListUsers -MaxRecords 100
# Query specific data sources only (not all)
.\users\users.ps1 -IncludeEntraID -ListUsers # Not: -IncludeEntraID -IncludeAD -IncludeLocalProblem: Compliance CSV not created
Solution:
Add -IncludeExportFormats parameter:
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "All" -ExportExcel -ExcelPath ".\Report.xlsx" -IncludeExportFormatsProblem: Cannot get MFA authentication methods
Solution:
# Reconnect with proper scopes
Disconnect-MgGraph
Connect-MgGraph -Scopes "User.Read.All", "UserAuthenticationMethod.Read.All"
# Then run the script
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeMFADetailsCreate custom profile scripts:
# Create profile for daily checks
function Daily-SecurityCheck {
.\users\users.ps1 -IncludeEntraID -ListUsers `
-UseCache `
-FilterByRiskLevel "Critical" `
-ExportExcel -ExcelPath ".\Daily_$(Get-Date -Format 'yyyy-MM-dd').xlsx"
}
# Create profile for compliance
function Compliance-Report {
param([string]$Framework = "All")
.\users\users.ps1 -IncludeEntraID -IncludeAD -ListUsers `
-ComplianceFramework $Framework `
-ExportExcel -ExcelPath ".\Compliance_$Framework_$(Get-Date -Format 'yyyy-MM-dd').xlsx" `
-IncludeExportFormats
}
# Add to your PowerShell profile
# notepad $PROFILEExport to JSON for SIEM/monitoring tools:
# Generate JSON for automation
.\users\users.ps1 -IncludeEntraID -ListUsers `
-IncludeRiskScore `
-ExportExcel -ExcelPath ".\Report.xlsx" `
-IncludeExportFormats
# Parse JSON and send alerts
$data = Get-Content "Users_List_*.json" | ConvertFrom-Json
$critical = $data.UserData | Where-Object { $_.RiskLevel -eq "Critical" }
if ($critical.Count -gt 0) {
# Send to monitoring system
Invoke-RestMethod -Uri "https://monitoring.company.com/api/alerts" `
-Method Post `
-Body ($critical | ConvertTo-Json) `
-ContentType "application/json"
}Create scheduled tasks:
# Weekly compliance report
$Action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-File C:\ITAuditKit\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework 'All' -ExportExcel -ExcelPath 'C:\Reports\Weekly_Compliance.xlsx'"
$Trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 6am
Register-ScheduledTask -TaskName "Weekly_Compliance_Report" -Action $Action -Trigger $Trigger -Description "Weekly compliance audit report"Combine multiple filters:
# Complex filter: IT department, privileged, no MFA, active in last 30 days
.\users\users.ps1 -IncludeEntraID -ListUsers `
-FilterByDepartment "IT" `
-ShowOnlyPrivileged `
-ShowOnlyNoMFA `
-LastLoginAfter (Get-Date).AddDays(-30) `
-ExportExcel -ExcelPath ".\IT_Privileged_NoMFA_Active.xlsx"Best practices for large environments:
# Use caching for repeated queries
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -CacheExpiryMinutes 120
# Process in batches
.\users\users.ps1 -IncludeEntraID -ListUsers -MaxRecords 500 -ExportExcel -ExcelPath ".\Batch1.xlsx"
# Target specific departments
$departments = @("IT", "Finance", "HR", "Sales")
foreach ($dept in $departments) {
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCache -FilterByDepartment $dept -ExportExcel -ExcelPath ".\$dept`_Report.xlsx"
}# Get detailed help for the script
Get-Help .\users\users.ps1 -Full
# Get help for specific parameter
Get-Help .\users\users.ps1 -Parameter ComplianceFramework
# List all available parameters
Get-Help .\users\users.ps1 -Parameter *This project is licensed under the GNU GENERAL PUBLIC LICENSE Version 3 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
# Basic user list
.\users\users.ps1 -IncludeEntraID -ListUsers
# With Excel export
.\users\users.ps1 -IncludeEntraID -ListUsers -ExportExcel -ExcelPath ".\Report.xlsx"
# Find users without MFA
.\users\users.ps1 -IncludeEntraID -ListUsers -ShowOnlyNoMFA
# Generate SOX compliance report
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "SOX" -ExportExcel -ExcelPath ".\SOX.xlsx"
# Find inactive accounts
.\users\users.ps1 -IncludeEntraID -ListUsers -InactiveDays 90
# High-risk accounts
.\users\users.ps1 -IncludeEntraID -ListUsers -IncludeRiskScore -FilterByRiskLevel "Critical"
# Department audit
.\users\users.ps1 -IncludeEntraID -ListUsers -FilterByDepartment "IT" -ExportExcel -ExcelPath ".\IT_Audit.xlsx"
# Complete audit package
.\users\users.ps1 -IncludeEntraID -ListUsers -ComplianceFramework "All" -ExportExcel -ExcelPath ".\Full_Audit.xlsx" -IncludeExportFormats
# Fast repeated queries
.\users\users.ps1 -IncludeEntraID -ListUsers -UseCacheVersion: 1.5.0
Last Updated: October 16, 2025
PowerShell Version Required: 7.0+
Status: Production Ready
For the most up-to-date information and additional examples, refer to the documentation files in the users/ directory.
Happy Auditing! π