AntiMalware Status

Report on user count in Active Directory with PowerShell

Here is quick PowerShell script that provides information on user count in Active directory:

  • 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.

# Import the Active Directory module if not already loaded
if (-not (Get-Module ActiveDirectory)){
Import-Module ActiveDirectory -ErrorAction Stop

Write-Host ACTIVE DIRECTORY USER COUNT -ForegroundColor white -BackgroundColor red
Write-Host Users in AD including Disabled users: (Get-ADUser -filter *).count

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 ="

            table {<br />                border-collapse: collapse;<br />            }<br />            td, th {<br />                border: 1px solid black;<br />            }<br />        </style></header>&nbsp;
<td>Total Number of All user accounts in Active Directory</td>
<td>Total Number of Enabled Users in Active Directory</td>
<td>TotalNumber of Disabled Users in Active Directory</td>

$html | Out-File "TotalUsersADReport.html"

Write-host =&gt; Report TotalUsersADReport.html has been created ! .... -f yellow

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.