array comparison

I am trying to compare a list of servers in a windows security group to a list of servers in my SQL CMS group (Central Management Server). I get the idea of how to compare 2 arrays…

$a = 1,2,3,4,5
$b = 4,5,6,7,8
$Yellow = $a | Where {$b -NotContains $_}
$Blue = $b | Where {$a -NotContains $_}

But it doesn’t work with my server names. How do I troubleshoot?

$CMSservers  = Get-DbaCmsRegServer -SqlInstance localhost -Group MyCMSgroup | Select-Object -ExpandProperty ServerName
$ADlist = Get-ADGroupMember -identity "WindowsGroupName" -Recursive | select name 

The yellow/blue comparison from above returns a full list of items in each of the array.

You should read the help for Compare-Object. It’s made for comparison of objects. :wink:

You’re comparing properties that have different names (servername vs name)
Try comparing these 2 lists:

$CMSservers  = (Get-DbaCmsRegServer -SqlInstance localhost -Group MyCMSgroup).ServerName
$ADlist = (Get-ADGroupMember -identity "WindowsGroupName" -Recursive).name