Created
August 2, 2016 21:10
-
-
Save codewithtyler/24ed7e198a8a444f618343da032dfe55 to your computer and use it in GitHub Desktop.
Counts the number of users for a given Active Directory domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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