A number of ways exist to create arrays. An empty array (containing no elements) can be created the same as the following:
$myArray = @()
An empty array of a specific size may be created using New-Object. Using [] after the name of the type denotes that it is an array, and the number following sets the array size:
$myArray = New-Object Object[] 10 # 10 objects $byteArray = New-Object Byte[] 100 # 100 bytes $ipAddresses = New-Object IPAddress[] 5 # 5 IP addresses
An array with a few strings in it can be created the same as this:
$myGreetings = "Hello world", "Hello sun", "Hello moon"
Or the same as this:
$myGreetings = @("Hello world", "Hello sun", "Hello moon")
An array may be spread over multiple lines in either the console or a script that may make it easier to read in a script:
$myGreetings = "Hello world", "Hello sun", "Hello moon"
You can mix values that are considered to be objects without losing anything:
$myThings = "Hello world", 2, 34.23, (Get-Date)