I have 2 arrays, each entry holding multiple values.
$Info holds the results of a AD query:
$Info = (Get-ADComputer -Filter "Description -like '*Failover cluster*'" -properties comment | ? comment -ne $null | Select name, @{L="OwnerNode";E={($_.comment).Trim()}})
name OwnerNode ---- --------- SQL-P03 NODE-P03 SQL-P04 NODE-P01 SQL-P05 NODE-P04 SQL-P06 NODE-P04 SQL-P07 NODE-P02 SQL-T01 NODE-T03 SQL-T02 NODE-T02 SQL-T03 NODE-T01 SQL-T98 NODE-T01 SQL-T99 NODE-T02
$Current holds the output of querying the Cluster:
$Current = @() foreach($Cluster in $Clusters){ $Current += Get-ClusterResource -Cluster $Cluster | ?{$_.Name -Match "SQL Network Name"} | Select @{L="SqlServer"; E={(($_.Name.split("(")[1]).Replace(")","")).Trim()}},OwnerNode }
SqlServer OwnerNode --------- --------- SQL-P03 NODE-P03 SQL-P04 NODE-P01 SQL-P05 NODE-P04 SQL-P06 NODE-P04 SQL-P07 NODE-P02 SQL-T01 NODE-T03 SQL-T02 NODE-T02 SQL-T03 NODE-T01 SQL-T98 NODE-T02 SQL-T99 NODE-T01
In this case the Sql Servers “SQL-T98” & “SQL-T99” have different values between their current Host and the value of Comment in AD.
What I’m trying to do is get output that says, in effect, server SQL-T99 is on Node-T01 but should be on Node-T02.
I’ve tried using Compare-Object which does give me the correct differences but the output is such that I’m struggling to find a way to use it.
(Compare-Object (($Current | Sort SqlServer) | ConvertTo-CSV -NoTypeInformation ) (($info | Sort name) | ConvertTo-CSV -NoTypeInformation)).inputObject
“name”,“OwnerNode”
“SQL-T98”,“NODE-T01”
“SQL-T99”,“NODE-T02”
“SqlServer”,“OwnerNode”
“SQL-T98”,“NODE-T02”
“SQL-T99”,“NODE-T01”
I’m hoping to get a way to compare the two arrays and when a difference is found, get just the $Info.Name & $Info.OwnerNode of those entries that differ.