PowerCLI

 View Only
Expand all | Collapse all

Getting Notes field from PowerCli

RvdNieuwendijk

RvdNieuwendijkAug 27, 2013 07:54 PMBest Answer

  • 1.  Getting Notes field from PowerCli

    Posted Aug 27, 2013 07:42 PM

    I'm using $VMNotes = Get-VM myvm | Select-Object Notes in a script to pull the contents of the Notes field.  The returned data is:

    @{Notes=my notes

    }

    How do I get it to return just the contents of the notes field, without the @{Notes= }?



  • 2.  RE: Getting Notes field from PowerCli
    Best Answer

    Posted Aug 27, 2013 07:54 PM

    Try $VMNotes = Get-VM myvm | Select-Object -ExpandProperty Notes



  • 3.  RE: Getting Notes field from PowerCli

    Posted Aug 27, 2013 07:59 PM

    That did it.  Thanks!



  • 4.  RE: Getting Notes field from PowerCli

    Posted Apr 17, 2015 04:17 PM

    Hey Guys

    any idea what am i missing here ?

    the vm.notes attribute is only available if i remove the vm-guest filter

    Thanks

    Martin

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} | get-vmguest)) {

       

        write-host $vm.Hostname $vm.IPAddress $vm.OSFullName $Datacenter.name $Vm.Notes

       

      }

     

    }



  • 5.  RE: Getting Notes field from PowerCli

    Posted Apr 17, 2015 05:28 PM

    The VMGuest objects doesn't have the Notes property.

    You could do

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"}) {

            Get-VMGuest -VM $vm |

            Select Hostname,IPAddress,OSFullName@{N='Datacenter';E={$Datacenter.name}},@{N='Notes';E={$Vm.Notes}}

      }

    }


    Or (the VirtualMachine object is available under the VM property).

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} | Get-VMGuest) {

            Write-Host $vm.Hostname $vm.IPAddress $vm.OSFullName $Datacenter.name $Vm.VM.Notes

      }

    }



  • 6.  RE: Getting Notes field from PowerCli

    Posted Apr 17, 2015 05:47 PM

    Thanks Buddy !


    "$Vm.VM.Notes" did it for me...



  • 7.  RE: Getting Notes field from PowerCli

    Posted Apr 20, 2015 03:15 PM

    Hey Luc

    do you know why the csv output has just strings with  .Hashtable+KeyCollection ?

    i remember running a sort-table after the pipe to get the csv data normalized, but i cannot get it working

    since i need both console and csv outputs

    Thanks

    Martin

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} |get-vmguest)) {   

         write-host $vm.Hostname $vm.NumCPU $vm.IPAddress $vm.OSFullName $Datacenter.name $Vm.VM.Notes

        @{N="VM_NAME#";E={$vm.Hostname}},

        @{N="VM_CPU_Core#";E={$vm.NumCPU}},

        @{N="VM_IP#";E={$vm.IPAddress}},

        @{N="VM_OS";E={$vm.OSFullName}},

        @{N="VM_DC";E={$Datacenter.name}},

        @{N="VM_NOTES";E={$Vm.VM.Notes}}

        }

     

    }

    $VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "d:\temp\report.csv"



  • 8.  RE: Getting Notes field from PowerCli

    Posted Apr 20, 2015 03:42 PM

    Try like this

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} |get-vmguest)) {  

            $vm | Select @{N="VM_NAME#";E={$vm.Hostname}},

                @{N="VM_CPU_Core#";E={$vm.NumCPU}},

                @{N="VM_IP#";E={$vm.IPAddress}},

                @{N="VM_OS";E={$vm.OSFullName}},

                @{N="VM_DC";E={$Datacenter.name}},

                @{N="VM_NOTES";E={$Vm.VM.Notes}}

         }

    }

    $VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "d:\temp\report.csv"

     



  • 9.  RE: Getting Notes field from PowerCli

    Posted Apr 20, 2015 08:13 PM

    Thanks Luc !

    i added some trim at 30 chars on the "notes" since it was messing up with the formatting

    here is the working version in case anyone is interested

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM  |get-vmguest)) { 

            $vm | Select @{N="DEVICE_NAME";E={$vm.Hostname}},

            @{N="VM_VM_LABEL";E={$vm.VMname}},

            @{N="DEVICE_CPU_STATE";E={$vm.vm.PowerState}},   

                @{N="DEVICE_CPU_COUNT";E={$vm.VM.NumCPU}},   

            @{N="DEVICE_CPU_MEM_GB";E={$vm.VM.MemoryGB}},

            @{N="DEVICE_CPU_PROVISIONED_DISK";E={[math]::round($VM.vm.ProvisionedSpaceGB)}},

                @{N="DEVICE_IP";E={$vm.IPAddress}},

                @{N="DEVICE_OS";E={$vm.OSFullName}},

                @{N="DEVICE_DC";E={$Datacenter.name}},

                @{N="APPLICATION";E={$Vm.VM.Notes.remove(30)}}

         }

    }



  • 10.  RE: Getting Notes field from PowerCli

    Posted Mar 30, 2016 09:13 PM

    Hi Luc

    would you know by any chance what is the proper way to get to the notes inside the VMhost (not vm's) ?

    i need to use get-view to get some additional properties, but cant seem to find the proper way to

    query the notes of the ESX itself

    if i query get-vmhost |select customfields, they are there, but they dont show up under the view

    any ideas ?

    Thanks

    Martin

    $ESXInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {

            ForEach ($Cluster in ($Datacenter | Get-Cluster  | Sort-Object -Property Name)) {

             ForEach ($ESX in ($Cluster | Get-VMHost |Sort Name |Get-View )) {

             $ESX | Select @{N="DEVICE_NAME";E={$ESX.name}},

           @{N="DEVICE_STATE";E={$_.Summary.Runtime.PowerState}},

           @{N="DEVICE_MANUFACTURER";E={$_.Hardware.SystemInfo.Vendor}},

           @{N="DEVICE_MODEL";E={$_.Hardware.SystemInfo.Model}},

           @{N="DEVICE_VERSION";E={$_.Config.Product.Version}},

           @{N=“DEVICE_CPU_COUNT“;E={$_.Hardware.CpuInfo.NumCpuPackages}},

           @{N=“DEVICE_CPU_MEM_GB“;E={“” + (([math]::round($_.Hardware.MemorySize / 1GB, 0))* 1024/1024)}},

           @{N="DEVICE_CPU_PROVISIONED_DISK";E={}},

           @{N=“DEVICE_IP“;E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}},

           @{N=“DEVICE_OS“;E={$_.Config.Product.Name + $_.Config.Product.Version + “ - Build “ + $_.Config.Product.Build}},

           @{N="DEVICE_NOTES_TEST";E={$ESX.value.Notes}},

           @{N="DEVICE_NOTES_2";E={$ESX.CustomFields.Item("Notes")}}

         }

      }

    }

    $ESXInfo | Export-Csv -NoTypeInformation -UseCulture -Path "D:\temp\vmhost.csv"



  • 11.  RE: Getting Notes field from PowerCli

    Posted Mar 30, 2016 09:46 PM

    They should be under $esx.Summary.CustomValue



  • 12.  RE: Getting Notes field from PowerCli

    Posted Apr 01, 2016 09:29 PM

    Hey Luc,

    when doing a query on this one

    $esx.Summary.CustomValue i get VMware.Vim.CustomFieldStringValue on the csv

    am i missing anything ? i tried to call all properties on this attribute

    but cant seem to get this right...i can get the results, outside of the get-view

    but not using results within get-view

    maybe its cause its Friday...any ideas ?

    Thx

    Martin



  • 13.  RE: Getting Notes field from PowerCli

    Posted Dec 21, 2017 05:03 PM

    Hi LucD - This is pretty much what I am looking for but I can't get it to work. I am looking for a report that will pull all my VM's and provide the details for Name, OS, Notes, Tag, DataCenter and Cluster. The script you have below is close, however I am not sure how to get tags and cluster in it - and the export is not working either. Any help?

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} |get-vmguest)) { 

            $vm | Select @{N="VM_NAME#";E={$vm.Hostname}},

                @{N="VM_CPU_Core#";E={$vm.NumCPU}},

                @{N="VM_IP#";E={$vm.IPAddress}},

                @{N="VM_OS";E={$vm.OSFullName}},

                @{N="VM_DC";E={$Datacenter.name}},

                @{N="VM_NOTES";E={$Vm.VM.Notes}}

         }

    }

    $VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "d:\temp\report.csv"



  • 14.  RE: Getting Notes field from PowerCli

    Posted Dec 21, 2017 06:21 PM

    Try like this

    $VmInfo = ForEach ($Datacenter in (Get-Datacenter)) {

         ForEach ($VM in ($Datacenter | Get-VM | where {$_.powerstate -match "on"} | Get-VMGuest)) {

            $vm | Select @{N="VM_NAME#";E={$vm.Hostname}},

                @{N="VM_CPU_Core#";E={$VM.VM.NumCPU}},

                @{N="VM_IP#";E={$vm.IPAddress}},

                @{N="VM_OS";E={$vm.OSFullName}},

                @{N="VM_DC";E={$Datacenter.name}},

                @{N='VM_Cluster';E={(Get-Cluster -VM $VM.VM).Name}},

                @{N="VM_NOTES";E={$VM.VM.Notes}},

                @{N='VM_Tags';E={(Get-TagAssignment -Entity $VM.VM).Tag.Name -join '|'}}

         }

    }

    $VmInfo | Export-Csv -Path "d:\temp\report.csv" -NoTypeInformation -UseCulture



  • 15.  RE: Getting Notes field from PowerCli

    Posted Apr 29, 2020 01:48 PM

    Hi LucD,

    I have the below script running, however when ever I'm trying to add the nodes field it's not working.

    Get-VM | Sort-Object -property Name | Get-View -Property @("Name", "Guest.GuestFullName", "Guest.IPAddress", "VM.Notes") | Select -Property Name, @{N="Running-OS";E={$_.Guest.GuestFullName}},@{N="ip",E={$_.Guest.IPAddress -join '|'}}N,"notes descrp";E={$_.Guest.VM.Notes}} | Export-Csv -Path c:\temp\report.csv

    When I'm adding notes I'm getting error.

    Could you please help me on this.



  • 16.  RE: Getting Notes field from PowerCli

    Posted Apr 29, 2020 02:59 PM

    Since you are using Get-View the calculated property should be

    @{N='notes descrp';E={$_.Config.Annotation}}



  • 17.  RE: Getting Notes field from PowerCli

    Posted Dec 17, 2020 08:01 PM

    Correction: 

     

    Get-VM | Sort-Object -property Name | Get-View -Property @("Name", "Guest.GuestFullName", "Guest.IPAddress", "Config.Annotation") | Select -Property Name, @{N="Running-OS";E={$_.Guest.GuestFullName}},@{N="ip";E={$_.Guest.IPAddress -join '|'}},@{N="notes descrp";E={$_.Config.Annotation}}