Skip to content

Instantly share code, notes, and snippets.

@rezamt
Created June 1, 2018 01:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezamt/c4ca4f4cfd374c6da1ad5180a2bc3fa1 to your computer and use it in GitHub Desktop.
Save rezamt/c4ca4f4cfd374c6da1ad5180a2bc3fa1 to your computer and use it in GitHub Desktop.
Powershell HashTable Iteration
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