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

By Xah Lee. Date: . Last updated: .

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)
# create a empty array
$x = @();
$x.length

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

@(command)

# turn dir result into an array, and use array method length to get count
@(dir).length

PowerShell: Array

PowerShell

Practical How-To

list files

list dirs

on dir

on file

Windows config

zip tar

misc


PowerShell in Depth

Programing PowerShell

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples