PowerShell: Array Sub-Expression Operator @(), Collection to Array

By Xah Lee. Date: . Last updated: .

Array Sub-Expression Operator

Array can be created by the Array Sub-Expression Operator. It has the syntax


it forces the result to be an array.

$x = @(3, 4, 5)
# comma optional if in multi line
$x = @(

Create a Empty Array

# create a empty array
$x = @();

Convert Collection to Array

It is often used to turn a collection into an Array.


# turn dir result into an array, and use array method length to get count

PowerShell: Array