Another powershell pickle compare /exclude with pipes

Soldato
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
Really using up my PS quota q's this month!
Code:
$a = Get-XAWorkerGroup | ? {$_.WorkerGroupName -match "WK1"} | get-xaserver | select ServerName
$b = Get-XAWorkerGroup | ? {$_.WorkerGroupName -match "WK2"} | get-xaserver | select ServerName

Then in essence $b - $a = c$ stripped server list. (exclude servers from $a where exist in $b)

This produces a list of servers which sit in a WorkerGroup. However what I'm trying to do is also then compare that output with a similar query which pulls a server list from another workergroup and then produces a single list which excludes servers from the second workergroup which match servers in the first.

In this instance; clear as mud? :)

Cheers, Paul.

Code:
Compare-Object -referenceobject $a -differenceobject $b -includeequal | where {$_.sideIndicator -eq '=>'} | % {$_.InputObject}

Code:
Compare-Object -referenceobject $a -differenceobject $b | where {($_.SideIndicator -eq '=>') -And ($_.SideIndicator -ne '==')}| % {$_.InputObject}
This still outputs servers contained in both arrays but at least excludes the serves listed in the second array.

SOLUTION - Poor array control - I was only creating a single object in the array!
Code:
$a = Get-XAWorkerGroup | ? {$_.WorkerGroupName -match "WK1"} | get-xaserver | select -ExpandProperty ServerName
$b = Get-XAWorkerGroup | ? {$_.WorkerGroupName -match "WK2"} | get-xaserver | select -ExpandProperty ServerName

What a numpty!
 
Last edited:
Back
Top Bottom