Example: Create and Output Elements in an Array
$artists = @("Paul Simon","Eminem","Prince","James Brown")
$artists[0]
$artists[1]
Output:
Paul Simon
Eminem
Example: For Loop - Loop through an Array
$employees = @("Paul Smith","Mary Jones","Frank Hill","Amy Rodgers")
For ($i=0; $i -lt $employees.Length; $i++) {
$employees[$i]
}
Output:
Paul Smith
Mary Jones
Frank Hill
Amy Rodgers
Example: Adding Elements in an Array
$artists = @("Paul Simon","Eminem","Prince","James Brown")
$artists += "Maxwell"
$artists[4]
Output:
Maxwell
Example: Sorting an Array
$artists = @("Paul Simon","Eminem","Prince","James Brown")
$artists = $artists | sort
For ($i=0; $i -lt $artists.Length; $i++) {
$artists[$i]
}
Output:
Eminem
James Brown
Paul Simon
Prince