Create an Array

There are three methods to create and define an array. Based on these three methods, below are the three syntaxes of a PowerShell array:

In the first syntax, an array is created by enclosing the items in the @() parentheses.

$ArrayList = @('item 1', 'item 2', 'item 3')

The second syntax creates an array with items in a comma-separated list.

$ArrayList  = 'item 1', 'item 2', 'item 3'

The third syntax creates an array with a specific data type.

[ArrayType[]]$ArrayList = 'item 1', 'item 2', 'item 3'
PowerShell
Array

Comments