Search code examples
powershellpermissionscompareactive-directory-group

compare-object not displaying all differences


I have a new admin on our team, and she is having some permissions issues. Some things the new admin runs in Exchange PowerShell are giving weird errors that the rest of the team doesn't get, and google doesn't help with figuring out what those errors mean. So we figure it must be a permissions issue. In my investigation, I ran a query of the new admin's group membership, and then I wanted to compare it against mine. Everything seemed to work, however, I noticed the compare-object command didn't find all the differences when I spot checked the results.

Here is what I ran:

$a = Get-ADPrincipalGroupMembership "me" | select name

$b = Get-ADPrincipalGroupMembership "new admin" | select name

Compare-Object $a $b | ft -AutoSize

It listed about 7 results, but right away I noticed that I was in one group that started with an "A" and she wasn't in that group, and it was not listed in the results. Any suggestions?


Solution

  • Compare-Object was comparing two objects with Name properties. Still not completely sure why but the comparison is done better, in this case, with just straight strings. There are object based technet examples which is why I did't immediately assume it was related.

    $a = Get-ADPrincipalGroupMembership "me" | select -expandProperty name
    $b = Get-ADPrincipalGroupMembership "new admin" | select -expandProperty name
    
    Compare-Object $a $b | ft -AutoSize
    

    Or you could have used the -Property parameter of compare-object as well.

    $a = Get-ADPrincipalGroupMembership "me" 
    $b = Get-ADPrincipalGroupMembership "new admin"
    
    Compare-Object $a $b -Property Name | ft -AutoSize