We want to get a list of users with MFA status. By checking that, we…
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.
(Get-AdUser -Filter * | Measure-Object).Count
Count AD groups
Count AD groups with PowerShell. Use the Get-ADGroup cmdlet.
(Get-ADGroup -Filter * | Measure-Object).Count
Count AD computers
Count AD computers with PowerShell. Use the Get-ADComputer cmdlet.
(Get-ADComputer -Filter * | Measure-Object).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. You can also download Get-ADCount.ps1 script and run it from PowerShell.
$ADUser = (Get-AdUser -Filter * | Measure-Object).Count
$ADGroup = (Get-ADGroup -Filter * | Measure-Object).Count
$ADComputer = (Get-ADComputer -Filter * | Measure-Object).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer
$ADObjects
This is how it looks after you run the script. The total AD objects are 167.
PS C:\> $ADUser = (Get-AdUser -Filter *).Count
$ADGroup = (Get-ADGroup -Filter *).Count
$ADComputer = (Get-ADComputer -Filter *).Count
$ADObjects = $ADUser + $ADGroup + $ADComputer
$ADObjects
167
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.
C:\scripts\.\Get-ADInfo.ps1
This is how it looks.
Active Directory Info
Computers = 5
Workstions = 1
Servers = 4
Users = 74
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
RID Master = DC01-2019.exoip.local
PDC Emulator = DC01-2019.exoip.local
Infrastructure Master = DC01-2019.exoip.local
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 Check Exchange health mailboxes. Don’t forget to follow us and share this article.
Run to exclude disabled account:
(Get-ADUser -Filter "enabled -eq 'true'").Count
Thanks for this info, it really helped me out. Cheers!