0

In powershell i have two "tables" or lists, I am not sure about the right wording. One is obtained from a sharepoint list and the other from an sql table. Both lists have numbered elements which I can iterate through and each element has a bunch of named elements with a name and a value Fist question: what do you call this in powershell? (IN SQL I would simply call it table, in other programming languages probably something array of structs) Now what I want to do is to compare both lists based on two "columns" and find entries which are new or deleted in the second List. So what I can do is iterate through one List and compare each entry like this my code example. If both Lists are long, this takes really long and aditionally I have to do it a second time with both lists interchanged to find new AND deleted entries. I already tried to figure out if it can be done more efficient, probably with something like compare-object .... hope you guys have an idea!

ForEach ($Row in $Obj2) 
{ 

    $Cnt = ($Obj1 | Where-Object{$_["ID"] -eq $Row["P_ID"] -and $Row["ITEM"] -eq $_["part"]}).Count
        
    if ($Cnt -ne 1)
    {
        write-host do something
    }
}
Marek
  • 23
  • 5
  • I think we're going to need some example working dataset to work with. It looks like you're working with hashtables but I'm not convinced you are. – codaamok Apr 22 '22 at 20:49
  • 1
    Using this [`Join-Object script`](https://www.powershellgallery.com/packages/Join)/[`Join-Object Module`](https://www.powershellgallery.com/packages/JoinModule) (see also: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026)), something like: `$Obj1 |Join Obj2 -on id,part -eq p_id,item` – iRon Apr 23 '22 at 06:33

0 Answers0