I'm trying to speed up a script that gathers various tags and custom attributes. I managed to gather all tags into separate arrays which sped up the process significantly, Now, I want to do the same thing for custom attributes. With over 5,000 VM's, running Get-Annotation -Entity $Vm takes quite a while from start to finish. I only recently learned that the CustomFields are a part of the Get-VM results.
What I'd like to know, is how can I use the data that's already available?
# Get VM Info
$VMs = (Get-VM).where{$_.PowerState -eq 'PoweredOn' -or $_.PowerState -eq 'Suspended'}
foreach ($VM in $VMs) {
for ($i = 0; $i -lt $VMs.count; $i++){
if ($VMs[$i].Name -eq $VM) {
<magic here>
}
}
}
Viewing $VMs[0] |Select CustomFields shows each custom attribute, but I can't figure out how to get the values based on the name for each VM. I want to get the values for custom attributes "VM Owner" and "Application", for example.
Any assistance is appreciated. Thanks!