Creating an array

There are a number of ways to create arrays. An empty array (containing no elements) can be created as follows:

$myArray = @() 

An empty array of a specific size may be created using the 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 as follows:

$myGreetings = "Hello world", "Hello sun", "Hello moon" 

Or it can be created as follows:

$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) 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.71.237