Removing an element with a specific value from an array can be achieved in a number of different ways.
Again, starting with an array of 100 elements:
$oldArray = 1..100
Where-Object might be used to identify and omit the element with the value 50. If 50 were to occur more than once, all instances would be omitted:
$newArray = $oldArray | Where-Object { $_ -ne 50 }
The index of the element might be identified and removed using the methods explored in removing elements by the index:
$index = $oldArray.IndexOf(50)
If the value of the variable index is -1, the value is not present in the array (0 would indicate it is the first element):
$index = $oldArray.IndexOf(50) if ($index -gt -1) { $newArray = $oldArray[0..($index - 1)] + $oldArray[($index + 1)..99] }
Unlike the Where-Object version, which inspects all elements, IndexOf gets the first occurrence of a value only. A complementary method, LastIndexOf, allows the last occurrence of a value to be removed.