As our business continues to grow our focus is on providing white labeled Tier 3 IT support services, RMM as a service, and co-managed IT services. This blog will be highlighting tips for using Powershell to get an Active Directory User Count.
You need to find out what the Organizational Unit (OU) path that you are trying to get the count from. The following command will list all OUs in the domain.
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Format-Table Name, DistinguishedName -A
If you want the entire organization then you will need the top level information which looks like DC=[DomainName],DC=local
$SearchOU = This is the full DistinguishedName from the above output.
(Get-ADUser -Filter * -SearchBase $SearchOU).count
The script will take several seconds to run based on the number of users in the OU being searched. The output is an integer number. You can do the same sort of thing for an Active Directory Group Count or Active Directory Computer Count:
(Get-ADgroup -Filter * -SearchBase $SearchOU).count
(Get-ADcomputer -Filter * -SearchBase $SearchOU).count
If your company is a MSP or wants to become one and automation just seems out of reach, then contact us to run your RMM for you.