Hi. I use
Get-VM | Get-VMGuest | Format-Table VM, IPAddress
to get a table of VM names and associated IP address. I would like to get the NOTES too, however, it seems that
Get-VM | Get-VMGuest
has no such field. I know that I can separately use this loop to get VM notes
$VMList = Get-VM
Foreach ($vm in $VMList) {
$Note = $vm.Notes
}
but I would like to use that in the Format-Table as a column like vm name and ip.
Any way to fix that?
The object returned by Get-VMGuest contains the full VM object (under the VM property).
You can use a calculated property.
Get-VM |
Get-VMGuest |
Select VMName, IPAddress, @{N='Notes';E={$_.VM.Notes}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The object returned by Get-VMGuest contains the full VM object (under the VM property).
You can use a calculated property.
Get-VM |
Get-VMGuest |
Select VMName, IPAddress, @{N='Notes';E={$_.VM.Notes}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. It works.
I tried to sort the VMs based on the note column like this
Get-VM | Get-VMGuest | Sort -Property Notes | Format-Table -AutoSize VM, IPAddress , @{N='Notes';E={$_.VM.Notes}}
However, the output is not sorted.
VM IPAddress Notes
-- --------- -----
102.win7 {10.1.1.35, fe80::219d:5323:d65d:f644} February 16
104.win7 {10.1.1.22, fe80::8978:93e5:7e44:2227} March 03
107.win7 {10.1.1.37, fe80::5fb:2e71:4bd3:c467} February 12
106.u18 {10.1.1.24, fe80::250:56ff:feb9:4797} February 11
Any thoughts?
You could do
Get-VM | Get-VMGuest |
Select VMName, IPAddress , @{N='Notes';E={$_.VM.Notes}} |
Sort -Property Notes |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Right. Thanks.