Counting objects in Active Directory using PowerShell

Scenario:

The below basic script will deal only with counting objects in Active Directory using PowerShell. The commands in the script are able to perform the below.

Get instant information about the below:

Number of user objects in Active Directory

Number of computer objects in Active Directory

Number of groups in Active Directory and also separate them by distribution and security groups.

Related Links:

Solution / Script:

$Users = (Get-ADUSer -Filter *).count $Computers = (Get-ADComputer -Filter *).count $Groups = (Get-ADGroup -Filter *).count $Distribution_Groups = (Get-ADGroup -Filter {GroupCategory -eq "Distribution"}).count $Security_Groups = (Get-ADGroup -Filter {GroupCategory -eq "Security"}).count Write-Host "Number of users: $Users" Write-Host "Number of computers: $Computers" Write-Host "Number of groups: $Groups" Write-Host "Number of distribution groups: $Distribution_Groups" Write-Host "Number of security groups: $Security_Groups"