VMware Cloud Community
mahmn
Enthusiast
Enthusiast
Jump to solution

About getting VM notes

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?

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

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

mahmn
Enthusiast
Enthusiast
Jump to solution

Thanks. It works.

0 Kudos
mahmn
Enthusiast
Enthusiast
Jump to solution

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?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

mahmn
Enthusiast
Enthusiast
Jump to solution

Right. Thanks.

0 Kudos