#This script counts pcs per user. Enabled and disabled.
#If a user has no disabled PCs in AD, I get {} as result not 0. Why?
$samaccountnames = "abc","def","ghi"
foreach ($samaccountname in $samaccountnames)
{
$comps = Get-ADComputer -Filter * | Where-Object { $_.distinguishedname -like "*$samaccountname*"}
$count = $comps.count
$count_enabled = ($comps | Where-Object {$_.enabled -eq $true }).count
$count_disabled = ($comps | Where-Object {$_.enabled -eq $false}).count
$properties = [ordered]@{'user'=$samaccountname;
'PCs'=$count;
'PCs_enabled'=$count_enabled;
'PCs_disabled'=$count_disabled;
}
$obj = New-Object -TypeName PSObject -Property $properties
Write-Output $obj
}
Thanks.