0

I realize arrays are fixed-size collections. I am aware of how to manipulate their contents in various ways, change them into other array types, etc, but I can't figure out how to use the contents of one array to remove elements from another. For example, lets say we have this array:

$keep = "string1" , "string2" , "string3"

Then we build another array from something like a directory:

$collection = (get-childItem c:\directory1).Name

Now I want to make a third array by removing the three elements found in $keep from $collection:

$collection2 = $collection | Where-Object {$_.Name -ne $keep}

I cannot seem to get this to work. Lets just assume both of the first two arrays here are type object.

aleks.ko
  • 50
  • 8

1 Answers1

0

I think your question is related to this one

You could use something like this:

$keep = "1","2","3"
$list = "1","2","3","4","5","6"

$final = Compare-Object -ReferenceObject $list -DifferenceObject $keep
I.T Delinquent
  • 2,305
  • 2
  • 16
  • 33