Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

Script in powershell doesnt works fine

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...