skip to Main Content

Get Active Directory count with PowerShell

How to count Active Directory objects, and why do we need the AD objects count? In our example, we want to have the total count before we install and configure Azure AD Connect. That’s because we need to know the total AD objects for the minimum server requirements. In this article, we will look at how to count AD objects with PowerShell.

Count AD users

Count AD users with PowerShell. Use the Get-AdUser cmdlet.

PS C:\> (Get-AdUser -Filter *).Count

Count AD groups

Count AD groups with PowerShell. Use the Get-ADGroup cmdlet.

PS C:\> (Get-ADGroup -Filter *).Count

Count AD computers

Count AD computers with PowerShell. Use the Get-ADComputer cmdlet.

PS C:\> (Get-ADComputer -Filter *).Count

Get AD total count

Let’s add the user, group, and computer counts together with PowerShell. Use the below script, copy and paste it into PowerShell ISE. You can also download Get-ADCount.ps1 script and run it from PowerShell.

$ADUser = (Get-AdUser -Filter *).Count
$ADGroup = (Get-ADGroup -Filter *).Count
$ADComputer = (Get-ADComputer -Filter *).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer

This is how it looks after you run the script. The total AD objects are 5239.

PS C:\> $ADUser = (Get-AdUser -Filter *).Count
$ADGroup = (Get-ADGroup -Filter *).Count
$ADComputer = (Get-ADComputer -Filter *).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer

Get Active Directory info with PowerShell script

An excellent way to get the Active Directory count is to run the Get-ADInfo.ps1 PowerShell script. This will show the AD objects count and more information about your Active Directory.

PS C:\> cd C:\scripts
PS C:\scripts> .\Get-ADinfo.ps1

Active Directory Info

Computers =     8
Workstions =    3
Servers =       5
Users =         5143
Groups =        88

Active Directory Forest Name =   exoip.local
Active Directory Forest Mode =   Windows2016Forest
Active Directory Domain Mode =   Windows2016Domain
Active Directory Schema Version is 88 which corresponds to Windows Server 2019/Windows Server 2022

FSMO Role Owners
Schema master               DC01-2019.exoip.local
Domain naming master        DC01-2019.exoip.local
PDC                         DC01-2019.exoip.local
RID pool manager            DC01-2019.exoip.local
Infrastructure master       DC01-2019.exoip.local
The command completed successfully.

The below screen shows what it looks like.

Get Active Directory count with PowerShell script

That’s it! Did it help you to retrieve the total AD objects count?

Read more: Get total user count in Exchange »


You learned how to get Active Directory count with PowerShell. Count AD objects before you start deploying an application that uses the AD objects, and you want to know how many AD objects are present in AD. Another way is to run Get-ADInfo.ps1 PowerShell script to get the AD objects count and more information.

Did you enjoy this article? You may also like Count health mailboxes in Exchange. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has One Comment

Leave a Reply

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