I have a huge pscustomobject Array1
, and a second smaller Array2
containing text/strings. I want to remove objects from Array1 which have specific status in Array2. For example, remove from Array1 all elements with Array2.object.status = "Removed"
.
I don't want to create another Objects array using -contains
or -notcontains
. I know how to do it but I am looking for something more sophisticated, I was trying to convert my arrays to --> [System.Collections.ArrayList]
, like here --> $Array = [System.Collections.ArrayList]$Array
. I tried to use "Remove" and "RemoveAt" methods but still getting the same error
Error:
Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size.
Below please find extract from my code:
$Array1 = [System.Collections.ArrayList]$Array1
$Array1 = obj1, obj2, obj3 #contains pscustomobjects, with multiple
properties
$Array2 = text1, text2, text3 #contains status names, only strings/text
foreach ($element in $Array1) {
if ($Array2 -contains $element.status) {
$Array1.Remove($element)
}
}