VMware Cloud Community
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Get custom field information

For each of the VM's we have a custom field added in the notes section of VC called Created and the value is the date we created the VM, is there anyway to get a list of the machine name and the value of this custom field in a list type format similar to the below:

Get-VM | Select-Object -property "Name","PowerState","Description","NumCPU","MemoryMB"

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
1 Solution

Accepted Solutions
halr9000
Commander
Commander
Jump to solution

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)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000

View solution in original post

Reply
0 Kudos
2 Replies
halr9000
Commander
Commander
Jump to solution

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)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

As always a correct answer from halr9000, cant wait for the book !

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos