<<< Back to Search

Remove Element from Array

On this example element Apple is removed from array.

Example

# Declare array and initialize elements
$myArray = @("Banana","Apple","Lemon","Watermelon") 

# Write array piping output (Before Removal)
Write-Host "`r`nWrite array piping output(Before Remove Apple):`r`n"
$myArray | Out-String | Write-Host


# REMOVE ELEMENT (Apple) FROM ARRAY
$MyArrayNoApple = $myArray -ne "Apple"


# Write array piping output (After Removal)
Write-Host "`r`nWrite array piping output(After Remove Apple):`r`n"
$MyArrayNoApple | Out-String | Write-Host


Output

PS C:\> 

Write array piping output(Before Remove Apple):

Banana
Apple
Lemon
Watermelon


Write array piping output(After Remove Apple):

Banana
Lemon
Watermelon