To get aduser count results, get aduser active user count in the active directory, you can use the Get-AdUser with the Filter parameter and use Count to get ad user count.
While working with an active directory for aduser management, very often we need information like, get aduser count in OU, get aduser count for enabled users, get aduser count for the active users, etc…
In this article, we will discuss how to use the Get-AdUser Count field to get aduser count for users in OU and active users.
Get-AdUser Count in Active Directory
Use the Get-AdUser cmdlet with Filter * parameter to get one or more active directory users and use Count to get aduser count results.
(Get-AdUser -Filter *).Count
In the above PowerShell script, the Get-AdUser command gets active directory users, and using the Count, it returns the aduser count results.
The output of the above script to get active directory users count is:
PS C:\> (Get-AdUser -Filter *).Count
17
PS C:\>
Get-AdUser Count Users in OU
To get aduser count in OU, use the Get-AdUser SearchBase parameter to specify the OU and Count to get aduser counts in specific OU.
(Get-AdUser -Filter * -SearchBase "OU=SALES,DC=SHELLPRO,DC=LOCAL").Count
In the PowerShell script, the Get-AdUser uses the Filter * parameter to get all the users from OU specified by the SearchBase parameter and uses Count to get aduser count in OU.
The output of the above script to get aduser count in specific OU is:
PS C:\> (Get-AdUser -Filter * -SearchBase "OU=SALES,DC=SHELLPRO,DC=LOCAL").Count
3
PS C:\>
Get-ADUser Count Enabled User
To get the enabled aduser count in the active directory, use the Get-AdUser cmdlet with the Where condition to check if the Enabled attribute for the aduser object is true.
(Get-AdUser -Filter * | Where {$_.Enabled -eq "True"}).Count
In the above PowerShell script, the Get-AdUser uses the Filter parameter to retrieve adusers from the active directory and pipe it to the Where condition to check if the user is enabled using the Enabled attribute and get the enabled user count.
The output of the above PowerShell script to get aduser count active user is:
PS C:\> (Get-AdUser -Filter * | Where {$_.Enabled -eq "True"}).Count
13
PS C:\>
Conclusion
I hope the above article on how to get aduser count in the active directory for active, enabled status is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.