Report on user count in Active Directory with PowerShell

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.

[cc lang=”PowerShell”]
# 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 =”

 

Total Number of All user accounts in Active Directory $TotalAccounts
Total Number of Enabled Users in Active Directory $EnabledUsers
TotalNumber of Disabled Users in Active Directory $DisabledUsers

$html | Out-File “TotalUsersADReport.html”

Write-host
Write-host => Report TotalUsersADReport.html has been created ! …. -f yellow
[/cc]

Feel free to modify as you wish to your own needs.

Leave a Reply