February 2019
Intermediate to advanced
626 pages
15h 51m
English
A hashtable can return the information it holds in several ways. Start with the hashtable:
$hashtable = @{
Key1 = 'Value1'
Key2 = 'Value2'
}
Keys can be returned using the Keys property of the hashtable, which returns KeyCollection:
$hashtable.Keys
Values can be returned using the Values property, which returns ValueCollection. The key is discarded when using the Values property:
$hashtable.Values
A simple loop can be used to retain the association between key and value:
foreach ($key in $hashtable.Keys) {
Write-Host "Key: $key Value: $($hashtable[$key])"
}
Read now
Unlock full access