Migration to another mailbox database finished a couple of weeks ago. We like to remove…
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.
Table of contents
Count AD users
Count AD users with PowerShell. Use the Get-AdUser cmdlet.
PS C:\> (Get-AdUser -Filter *).Count
5143
Count AD groups
Count AD groups with PowerShell. Use the Get-ADGroup cmdlet.
PS C:\> (Get-ADGroup -Filter *).Count
88
Count AD computers
Count AD computers with PowerShell. Use the Get-ADComputer cmdlet.
PS C:\> (Get-ADComputer -Filter *).Count
8
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
$ADObjects
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
$ADObjects
5239
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.
That’s it! Did it help you to retrieve the total AD objects count?
Read more: Get total user count in Exchange »
Conclusion
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.
Thanks for this info, it really helped me out. Cheers!