Automation

 View Only
  • 1.  About getting VM notes

    Posted Feb 03, 2021 07:33 AM

    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?

     



  • 2.  RE: About getting VM notes
    Best Answer

    Posted Feb 03, 2021 07:47 AM

    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}}


  • 3.  RE: About getting VM notes

    Posted Feb 03, 2021 07:59 AM

    Thanks. It works.



  • 4.  RE: About getting VM notes

    Posted Feb 08, 2021 11:26 AM

    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?



  • 5.  RE: About getting VM notes

    Posted Feb 08, 2021 12:08 PM

    You could do

    Get-VM | Get-VMGuest | 
    Select VMName, IPAddress , @{N='Notes';E={$_.VM.Notes}} |
    Sort -Property Notes | 
    Format-Table -AutoSize

     



  • 6.  RE: About getting VM notes

    Posted Feb 08, 2021 12:51 PM

    Right. Thanks.