Arrays
An array contains a set of objects of the same type. Each entry in the array is called an element and each element has an index (position). Indexing in an array starts from 0
.
Arrays are an important part of PowerShell. When the return from a command is assigned to a variable, an array will be the result if the command returns more than one object. For example, the following command will yield an array of objects:
$processes = Get-Process
Note
Array type
:In PowerShell, arrays are, by default, given the type
System.Object[]
(an array of objects where []
is used to signify that it is an array).
Note
Why System.Object?
All object instances are derived from a .NET, type or class, and in .NET every object instance is derived from System.Object
(including strings and integers). Therefore, an array of System.Object
in PowerShell can hold just about anything.
Arrays in PowerShell (and .NET) are immutable, and the size is declared on creation and it cannot be changed. A new array must be created...