An array is an ordered collection of values. In PowerShell, comma-separated values automatically form an array, and a parameter such as String[] can accept one or many strings. section 3.5.4
Use arrays to work with several values at once:
- Create one with a comma-separated list, such as five strings or the range 1..10. section 3.5.4 section 23.1.1
- Access an individual element with its index, such as $array[0]. section 26.2.3
- Iterate through every element with foreach, which runs its script block once per collection item. section 23.1.1
- Convert between arrays and delimited strings with -join and -split. section 26.2.3
Split a tab-delimited record
$array = (gc computers.tdf) -split "`t"; $array[0] returns the first field, such as Server1. Use -join to combine array elements into a pipe-delimited string for reuse or output to a file. section 26.2.3
PS C:\> $array = "one","two","three","four","five" PS C:\> $array one two three four five
Run the supplied PowerShell example to create and display a five-element array before transforming it. section 26.2.3







































