I know that this question has already been answered for hashtable keys... but it does not seem to work for hashtable values.
I'm creating a hash of VM's based on the cluster they reside in. So the hashtable looks like this
$clusters[$clustername][$clustervms] = @{}
The reason each VM is a hashtable is because i'm trying to associate it with their VM tag as well (vmware).
This code works incredibly fast but destroys the keys, by injecting values as keys... or in other words, Rather than key/value pairs - values become keys, keys become values ... it's just a shit show.
foreach ($value in $($clusters.values)) {
$clusters[$value] = (get-tagassignment -entity ($value).name).tag
This code works - but it is unbelievably slow.
foreach ($key in $($clusters.keys)) {
$vms = (Get-Cluster -Name $key | Get-Vm).name
foreach ($vm in $vms) {
$clusters[$key][$vm] = @{};
$tag = (Get-TagAssignment -Entity $vm).tag;
$clusters[$key][$vm] = $tag;
}
}
When i say unbelievably slow - i mean getting the VM names takes about 5 seconds. Getting the tag assignments through the first code (codename: shit show) takes about 7 seconds. I've waited a minute on this code, and it's only gone through 6 VM's in that time. So i know there's a better way.
Thanks,