Remove item from array
#Convert array to ArrayList to use 'Remove' function
[System.Collections.ArrayList]$array = @("first", "second", "third", "fourth")
$array
$arrayBefore = $array #this creates connection - when removed from array, removed also from arrayBefore
$nextArray = $array.Clone() #creates copy without connection
$array.RemoveAt(2)
$array.Remove("fourth")
$array.IndexOf("first")
"`nArray"
"======"
$array
"`nArrayBefore"
"======"
$arrayBefore
"`nNextArray"
"======"
$nextArray
Output:
first
second
third
fourth
0
Array
======
first
second
ArrayBefore
======
first
second
NextArray
======
first
second
third
fourth