Powershell - Hash Table (Map)

Windows Powershell Menu

Powershell - Hash Table (Map)

About

Collection - Map (Associative arrays|Dictionary) in powershell is implemented as a Hash Table.

Management

Init

$hash = @{ Number = 1; Shape = "Square"; Color = "Blue"}
$hash = [ordered]@{ Number = 1; Shape = "Square"; Color = "Blue"}
$hash
Name                           Value
----                           -----
Number                         1
Shape                          Square
Color                          Blue

Iterating

$hash.Keys | % { "key = $_ , value = " + $hash.Item($_) }
  • Key
foreach ($key in $hash.Keys) {
    Write-Host "${key} , $($hash.Item($key))"
}
  • Entry
foreach ($entry in $hash.GetEnumerator()) {
    Write-Host "$($entry.Name) , $($entry.Value)"
}

Documentation / Reference







Share this page:
Follow us:
Task Runner