Counting the Number of AD User Accounts in PowerShell

powershell cim 1 600x337 - Counting the Number of AD User Accounts in PowerShell

Here are some PowerShell examples that we can use to count the numbers of user accounts in Active Directory.

Total number of user accounts in AD

PS> (Get-ADUser -filter *).count

Total number of user accounts in an OU

PS> (Get-ADUser -filter * -searchbase "OU=Vancouver, OU=MyCompany, DC=Domain, DC=Local").count

Replace the SearchBase with your own OU path.

Total number of enabled/disabled accounts in AD

PS> (Get-AdUser -filter * |Where {$_.enabled -eq "True"}).count
PS> (Get-ADUser -filter * |Where {$_.enabled -ne "False"}).count

Total number of user accounts in a Group

PS> (Get-ADGroupMember -Identity "Group Name").count

PowerShell count AD User Accounts - Counting the Number of AD User Accounts in PowerShell

I ran these on a Windows 10 machine. If you get an error message saying the unrecognized command, follow this instruction to get PowerShell Active Directory Module installed.

Leave a Reply

Your email address will not be published. Required fields are marked *