Created
June 1, 2018 01:34
-
-
Save rezamt/c4ca4f4cfd374c6da1ad5180a2bc3fa1 to your computer and use it in GitHub Desktop.
Powershell HashTable Iteration
This file contains 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