I have this script to count how many users are in each OU. The script works fine except if the number of users are one. If the numbers of users is two or more print the result ok but if is one it prints this phrase:
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection users
Anyone Knows the reason?
Script:
"OU=RDS Funcional,DC=esofitec,DC=loc","OU=VDI Funcional,DC=esofitec,DC=loc" | ForEach-Object {
Get-ADOrganizationalUnit -Filter * -SearchBase $_ | ForEach-Object {
$users = Get-ADUser -Filter "Name -notlike 'test*' -and Name -notlike 'adm*'" -SearchBase $_.distinguishedname
[PSCustomObject]@{
OU = $_.name
Users = "{0} users" -f $users.count
}
}
} | Export-Csv -Path c:est.csv -NoTypeInformation -Delimiter ','
Here what print the script in the export file:
2891 Ferraz Microsoft.ActiveDirectory.Management.ADPropertyValueCollection users
3387 Centre Assessor Gilabert Tarrega 5 users
4634 Grupo Neogest 3 users
4639 Fine Home Microsoft.ActiveDirectory.Management.ADPropertyValueCollection users
Best and Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…