Find the missing machine

This topic contains 8 replies, has 3 voices, and was last updated by Profile photo of carl trevett carl trevett 5 months, 3 weeks ago.

  • Author
    Posts
  • #55079
    Profile photo of carl trevett
    carl trevett
    Participant

    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

  • #55080
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

  • #55081
    Profile photo of carl trevett
    carl trevett
    Participant

    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

  • #55082
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #55086
    Profile photo of carl trevett
    carl trevett
    Participant

    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.

  • #55091
    Profile photo of carl trevett
    carl trevett
    Participant

    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

  • #55094
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Just add some verbose output. "Now checking array 1..." etc.

  • #55102
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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 ",")
    
    }
    
  • #55103
    Profile photo of carl trevett
    carl trevett
    Participant

    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?

    • This reply was modified 5 months, 3 weeks ago by Profile photo of carl trevett carl trevett.

You must be logged in to reply to this topic.