PowerShell Arrays for Beginners
In this short video, I walk through the fundamentals of working with PowerShell arrays. If you’re just getting started, this is a great place to begin.
👉 Watch here: PowerShell Arrays for Beginners
Topics Covered in the Video
-
Declare an empty array
$myArray = @()
-
Populate the array with strings
$myArray = "zero", "one", "two"
-
Access elements by index
-
First element (
0
), last element (-1
), or any position:$myArray[0] # zero $myArray[-1] # two
-
-
Select multiple elements
$myArray[0,2] # zero and two $myArray[1..3] # one, two, three
-
Add elements with
+=
(recreates the array each time — fine for small lists)$myArray += "three"
-
Inspect the variable type
$myArray.GetType()
-
List available members
$myArray | Get-Member
-
Check array length
$myArray.Length
-
Clear the array
$myArray.Clear()
-
Review and reuse console history
Get-History # alias: h Invoke-History 3 # alias: r 3
-
Join array elements into a string
$joined = $myArray -join ", "
-
Split a string back into an array
$newArray = $joined -split ", "
Arrays are one of the most common and useful data structures you’ll use in PowerShell scripting—get to know them well. Thanks for watching!