← Knowledge Base
PowerShellReference note1 min read · updated 2026-11-27

PowerShell variables, arrays and hashtables

The basic data types and how to loop over them.

powershellscripting
$name = 'George'
"Hello $name"                      # double quotes expand variables; single quotes do not
$items = @('a', 'b', 'c')
$items += 'd'
$items[0]; $items.Count
$h = @{ Name = 'srv1'; Port = 443 }
$h['Name']; $h.Port
$h.Keys

foreach ($i in $items) { Write-Host $i }
1..5 | ForEach-Object { $_ * 2 }
$env:PATH                          # environment variable
[int]'42' + 1                      # type conversion

Use $PSItem or $_ for the current pipeline object. Write-Output returns data to the pipeline; Write-Host only prints. Strict mode catches typos: Set-StrictMode -Version Latest.