Most efficient way to remove instances from collections

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5751

    by Lembasts at 2013-04-02 17:37:51

    Greetings,

    Let's say I had a 'Master' collection that contained a computername property and dozens of other properties.
    Then let's say I had a 'transaction' collection that contained a computername property and dozens of other properties.

    I want to remove all instances in the 'Master' collection where the computername matches one that exists in the 'transaction' collection. (For this comparison I dont care about the other properties)
    All 'Master' collection properties for the remaining instances need to be preserved.

    I have tried some nasty coding loops to achieve this but im wondering what would be the most efficient way of coding this?

    by mjolinor at 2013-04-02 17:52:51

    I'd think this would work:

    $computerlist = $transactions |
    select -ExpandProperty computername -Unique

    $Newmaster = $master |
    where {$computerlist -notcontains $_.computername}

    by Lembasts at 2013-04-02 17:56:42

    Thanks heaps. I was trying something with notcontains but I couldnt get a straight list of computernames. It was the expandproperty that I needed!!!

You must be logged in to reply to this topic.