methuselah
methuselah

Reputation: 13206

Reading key values from hash table in Powershell

How would I go about reading all the key values in a hash table? I'm currently trying the below and it returns nothing.

$dict = @{}    

Import-CSV hostname.csv | ForEach-Object {
        if ($dict.Keys -contains $_.type) {
            $dict[$_.type]+=$_.hostname
        } else {
            $dict[$_.type] = @($_.hostname)
        }
    }

$dict.Keys | ForEach-Object {
    Write-Host $_hostname
}

Upvotes: 0

Views: 2203

Answers (1)

Musaab Al-Okaidi
Musaab Al-Okaidi

Reputation: 3784

Replace:

$dict.Keys | ForEach-Object {
    Write-Host $_hostname
}

with:

$dict.Keys | ForEach-Object {
    Write-Host $dict[$_]
}

Upvotes: 2

Related Questions