Skip to main content

Array - PowerShell

Ref: about_Arrays

Ref: help about_Arrays

$array = <value>, <value>[, ...]
$array = @([<value>[, ...]])

Range

$array = <start>..<end>

Count

$array.Count

Get element

$array[<index>]

Set element

$array[<index>] = <value>

Slice

$array[<index>..<index>]

Iteration

foreach ($element in $array) {
# $element
}

$array.ForEach({
# $PSItem == $_ == <current element>
})

Filter

$array.Where({
# $PSItem == $_ == <current element>

# Filter out if expression is [0, "", $false, $null]
})