Count Number of AD Users – PowerShell

Very quick piece of PowerShell that will count the number of AD Users in your domain

(get-aduser -Filter * ).count

We can then extend this to only count the Enabled AD users

(get-aduser -filter {enabled -eq $true}).count

This is all well and good but we want to dive deeper and search on multiple OUs.

So, letsĀ  search in multiple OUs, and only count the Enabled AD users;

OUs$ = "CN=Users,DC=Lab,DC=net", "OU=TestUsers,DC=Lab,DC=net"

$OUs | ForEach-Object{
          OU = $_
          Count = (Get-Aduser -Filter {enabled -eq $true} -SearchBase "$_").count




Leave a Reply

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