Skip to content

Instantly share code, notes, and snippets.

@codewithtyler
Created August 2, 2016 21:10
Show Gist options
  • Save codewithtyler/24ed7e198a8a444f618343da032dfe55 to your computer and use it in GitHub Desktop.
Save codewithtyler/24ed7e198a8a444f618343da032dfe55 to your computer and use it in GitHub Desktop.
Counts the number of users for a given Active Directory domain
Import-Module ActiveDirectory
$domain = Get-ADOrganizationalUnit -searchbase "DC=contoso, DC=com" -filter * -searchscope 1
$total = 0
foreach ($ou in $domain)
{
$count = @(Get-ADUser -searchbase $ou -filter * |Where-Object {$_.enabled -eq "true"}).count
$total += $count
}
Clear-Host
Write-Host # Write a blank line
Write-Host $total "users total"
Write-Host # Write a blank line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment