Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Comparing two users group membership

$
0
0

I am trying to come up with some task to learn PS. I had a request to get users memberof.

I thought why not script comparing two users groups.

Not happy with the output so far:

$FirstUser = Read-Host "Enter Fisrt Users Name"

$SecondUser = Read-Host "Enter Fisrt Users Name"

#Collect Fisrt Users Groups

$FirstUserGroups = Get-ADPrincipalGroupMembership $FirstUser | select name

#Collect Second Users Groups

$SecondUserGroups = Get-ADPrincipalGroupMembership $SecondUser | select name

#Compare Arrays

$Difference = Compare-Object $FirstUserGroups $SecondUserGroups

I would like to see User1 is not in ClientEngineering

and                       User2 is not in techsupport.

 

A bit lost at the moment what needs to be changed.

Thanks for the help.


Viewing all articles
Browse latest Browse all 6937

Trending Articles