July 2017
Intermediate to advanced
648 pages
31h 9m
English
Let's start off by looking at how arrays work in PowerShell. When working with arrays, you can access specific items and add or remove elements. In our first example, we assigned a list of server names to the $servers array. To view all of the items in the array, simply type the variable name and hit return:
[PS] C:\>$servers
EX1
EX2
EX3
Array indexing allows you to access a specific element of an array using its index number inside square brackets ([]). PowerShell arrays are zero-based, meaning that the first item in the array starts at index zero. For example, use the second index to access the third element of the array, as shown next:
[PS] C:\>$servers[2]
EX3
To assign a value to a specific element of the array, use ...
Read now
Unlock full access