Here is quick [easyazon_link identifier=”1787122042″ locale=”US” tag=”wn0d5-20″] PowerShell [/easyazon_link] script that provides information on user count in [easyazon_link identifier=”1782175997″ locale=”US” tag=”wn0d5-20″] Active directory [/easyazon_link]:
- Total Number of All user accounts
- Total Number of Enabled accounts
- TotalNumber of Disabled accounts
It outputs in to formatted table in html so you can send in email as attachment or just keep for records in share drive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # Import the Active Directory module if not already loaded if (-not (Get-Module ActiveDirectory)){ Import-Module ActiveDirectory -ErrorAction Stop } Write-Host Write-Host ACTIVE DIRECTORY USER COUNT -ForegroundColor white -BackgroundColor red Write-Host Users in AD including Disabled users: (Get-ADUser -filter *).count Write-Host Write-Host ENABLED vs. DISABLED -ForegroundColor White -BackgroundColor Red Write-Host ENABLED : (Get-AdUser -filter * | Where {$_.enabled -eq "True"}).count Write-Host DISABLED: (Get-ADUser -filter * | Where {$_.enabled -ne "False"}).count $TotalAccounts = (Get-ADUser -filter *).count $EnabledUsers = (Get-AdUser -filter * | Where {$_.enabled -eq "True"}).count $DisabledUsers = (Get-ADUser -filter * | Where {$_.enabled -ne "False"}).count #export to HTML Report $html =" <header><style> table {<br /> border-collapse: collapse;<br /> }<br /> td, th {<br /> border: 1px solid black;<br /> }<br /> </style></header> <table> <tbody> <tr> <td>Total Number of All user accounts in Active Directory</td> <td>$TotalAccounts</td> </tr> <tr> <td>Total Number of Enabled Users in Active Directory</td> <td>$EnabledUsers</td> </tr> <tr> <td>TotalNumber of Disabled Users in Active Directory</td> <td>$DisabledUsers</td> </tr> </tbody> </table> " $html | Out-File "TotalUsersADReport.html" Write-host Write-host => Report TotalUsersADReport.html has been created ! .... -f yellow |
Feel free to modify as you wish to your own needs.