Here's how to read it:
$vm = get-vm fooVM
$vm.CustomFields.Item("keyName")
Here's how to do it in a table:
56# Get-VM adama* | Select-Object -property "Name","PowerState","Description","NumCPU","Memor
yMB", { $_.CustomFields.Item("dhcp") }
Name : Adama_win2k3
PowerState : PoweredOn
Description :
NumCpu : 1
MemoryMB : 596
$_.CustomFields.Item("dhcp") : 1
57# Get-VM adama* | Select-Object -property "Name","PowerState","Description","NumCPU","Memor
yMB", { $_.CustomFields.Item("dhcp") } | ft
Name PowerState Description NumCpu MemoryMB $_.CustomField
s.Item("dhcp")
---- ---------- ----------- ------ -------- --------------
Adama_win2k3 PoweredOn 1 596 1
To make it prettier, add a hashtable object holding the name of the new property and the expression used to generate it. Like so:
$CustomFieldExp = @ { Name = "My Key"; Expr = { $_.CustomFields.Item("keyName") } }
Get-VM | Select-Object -property "Name","PowerState","Description","NumCPU","MemoryMB", $CustomFieldExp
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)