Find the missing machine

Hi

I have 4 sets of data (machine names from different products) the machine names should exist in all 4 data sets. I am trying to output the data into 4 columns and if a machine name is missing from 1 data set a blank line is left so all results are aligned and easy to spot anything missing. Can someone please help?

Thanks
Carl

Not knowing what the data looks like, I’d ordinarily use Compare-Object.

4 arrays(string) with machine names

$1 = vm1,vm2,vm3,vm4
$2 = vm2,vm3,vm4,vm5
$3 = vm1,vm3,vm4,vm5
$4 = vm2,vm3,vm4,vm5

something like the above, I thought with compare-object you can only have one reference and one difference object

  1. Concatenate all the arrays into one.
  2. Run the combined array through Select -Unique
  3. The combined array now contains all possible names
  4. Compare each original array to the combo array to see what each one is missing.

Thanks that makes sense, don’t even want to let you know my ideas around it. Is there anyway to plot the data in csv:

$1,$2,$3,$4
Vm1, ,vm1
Vm2,vm2, ,vm2
Vm3,vm3,vm3,vm3
Vm4,vm4,vm4,vm4
,vm5,vm5,vm5

This way will be nice and easy to compare.

Probably taking the mick now, but thanks for all your help.

just got home and completed your 4 steps, you are right that does give me what’s missing from each original array. But for my clean up task I need to know which arrays they exist in so I can delete those objects before I can deploy the machines again…hope that makes sense

Just add some verbose output. “Now checking array 1…” etc.

It sounds like you are close. Here is a basic example of the steps:

$1 = "vm1", "vm2", "vm3", "vm4"
$2 = "vm2", "vm3", "vm4", "vm5"
$3 = "vm1", "vm3", "vm4", "vm5"
$4 = "vm2", "vm3", "vm4", "vm5"

$arrToCompare = $1, $2, $3, $4
#Concatenate all the arrays into one.
$combined = $1 + $2 + $3 + $4
#Run the combined array through Select -Unique (and ignore null values)
#The combined array now contains all possible names
$unique  = $combined | Where{ $_ } |Select -Unique

#Compare each original array to the combo array to see what each one is missing.
foreach ($arr in $arrToCompare) {
    
    $test = Compare-Object -ReferenceObject $arr -DifferenceObject $unique | Select -ExpandProperty InputObject
    "{0} does not contain {1}" -f ($arr -join ","), (@($test) -join ",")

}

Thanks Rob, that looks good but only issue is I’m dealing with 5000+ machines so the output is messy. still keen to get in a CSV format, like the below

set1,set2,set3,set4
vm1,    ,vm1,  
vm2,vm2,    ,vm2
vm3,vm3,vm3,vm3
vm4,vm4,vm4,vm4
   ,vm5,vm5,vm5

guessing this might not be possible?