Created
June 1, 2018 01:34
Powershell HashTable Iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to Iterate and find the keys and values inside: System.Collection.Hashtable | |
# System.Collections.Hashtable | |
# Accessing Keys and Values using Enumerator | |
(Get-AzureKeyVaultSecret -VaultName $KeyVaultName | Where 'ContentType' -eq 'Wrapped BEK').Tags | foreach { | |
foreach ($tag in $_.GetEnumerator()) | |
{ | |
if ($tag.Key -eq 'MachineName' -and $tag.Value -eq $VMName) { | |
Write-Host "$($tag.Key) = $($tag.Value)" | |
} | |
} | |
} | |
# Accessing Values without Enumerator | |
$DiskEncryptionKeyEncryptionKeyURL = ''; | |
(Get-AzureKeyVaultSecret -VaultName $KeyVaultName | Where 'ContentType' -eq 'Wrapped BEK').Tags | foreach { | |
# Write-Host $_["MachineName"] $_["VolumeLetter"] $_["DiskEncryptionKeyEncryptionKeyURL"] | |
if ($_["MachineName"] -eq $VMName -and $_["VolumeLetter"] -eq 'C:\') { | |
Write-Host $_["MachineName"] $_["VolumeLetter"] $_["DiskEncryptionKeyEncryptionKeyURL"] | |
$DiskEncryptionKeyEncryptionKeyURL = $_["DiskEncryptionKeyEncryptionKeyURL"]; | |
break; | |
} | |
} | |
$DiskEncryptionKeyEncryptionKeyURL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment