View Only
  • 1.  Creating equivalent vSphere Client report with PowerCLI

    Posted May 04, 2018 02:47 PM

    Perhaps this will offer a little bit of a challenge to some of you as it has me.  I'm trying to produce the same report that you can export from the vSphere Client (or web client) when you choose the Virtual Machines tab from either the Virtual Center Server, Datacenter, or Cluster objects.  You are able to customize it by adding or removing some columns and then export it in various formats.  I can't quite get it completely together, but I think I have a good start on this.

    I apologize for the formatting, but here is the code I have done thus far.  Unfortunately it doesn't get all of the data for some of my VMs even though the vSphere Client reports data.  Most notably the GuestOS.

    Does anyone have any idea what I might be missing or if there is a better way to do it?  I've included a table of the output below the code.

    EDIT: I noticed the table didn't show up very well so I captured a screenshot of the output as well as the table in the vSphere Client.



    &{get-vm |where-object {$_.VMHost.Parent -notlike "Excluded_Cluster_Here*"}|%{
    $VMID=Get-View ($
    new-object psobject -Property @{
    VM = $_
    PowerState = $_.Powerstate
    OverallStatus = $_.ExtensionData.OverallStatus
    VMHost = $_.VMHost
    ProvisionedSpace = $_.ProvisionedSpaceGB.ToString("#.##")
    UsedSpace = $_.UsedSpaceGB.ToString("#.##")
    CPUUsage = ($_ | Get-Stat -Stat cpu.usagemhz.average -maxsamples 1 -realtime|where{$_.instance -eq ""})
    MemUsage = ($_ | Get-Stat -Stat mem.usage.average -maxsamples 1 -realtime|where{$_.instance -eq ""})
    GuestOS = $_.ExtensionData.Guest.GuestFullName
    MemorySize = $_.MemoryMB
    CPUCount = $_.NumCpu
    Uptime = ($_ | Get-Stat -Stat sys.uptime.latest -maxsamples 1 -realtime|where{$_.instance -eq ""})
    IPAddress = $_.guest.ipaddress[0]
    DNSName = $_.ExtensionData.guest.hostname
    Notes = $_.Notes
    Cluster = $_.vmhost.Parent
    Version = $_.Version
    }|select VM,PowerState,OverallStatus,VMHost,ProvisionedSpace,UsedSpace,CPUUsage,MemUsage,GuestOS,MemorySize,CPUCount,Uptime,IPAddress,DNSName,Notes,Cluster,Version}
    }|Export-Csv 'L:\Excel Docs\vmgather.csv' -notypeinformation -useculture


    VUT-IT-LOG001-Nagios-Log-ServerPoweredOngreenmidvm42.local169.1567.242906553613012334Linux Clusterv7
    VMLXTEST-RHEL-TestPoweredOngreenmidvm53.local50.1822.40371.99Red Hat Enterprise Linux 6 (64-bit)204821026628810.8.1.245vmlxtest.localv8
    VWP-IT-APP046-Solarwinds-PollingPoweredOngreenmidvm35.local182.2168.4137634.99Microsoft Windows Server 2012 (64-bit)327684438611810.8.11.124VWP-IT-APP046.localProduction Clusterv9

  • 2.  RE: Creating equivalent vSphere Client report with PowerCLI

    Posted May 04, 2018 03:59 PM

    Try changing that line to

    GuestOS = $_.ExtensionData.Guest.OSFullName

    Any other properties you are looking for?

  • 3.  RE: Creating equivalent vSphere Client report with PowerCLI

    Posted May 04, 2018 05:22 PM

    Thanks for the reply. 

    Unfortunately that is empty for all of my VMs.  I tested with (get-vm).ExtensionData.Guest.OSFullName.  GuestFullName on the other hand has data for most of them, just not all of them.

    I guess I'm wondering where the vSphere Client is getting that Guest OS value from.

    Any other suggestions?

  • 4.  RE: Creating equivalent vSphere Client report with PowerCLI
    Best Answer

    Posted May 04, 2018 05:38 PM

    Oops, you are right, I messed up there.





    You do have VMware Tools installed and running on all these VMs?

    It's through there that the guest OS name is obtained.

    The VMs that do not show the OSFullName, are they powered on?

    The vCenter retains some info coming from VMware Tools for some time after a VM is powered off.

    While directly querying the object property will not show anything (consider that as 'live' data).

  • 5.  RE: Creating equivalent vSphere Client report with PowerCLI

    Posted May 04, 2018 07:05 PM

    We're getting closer.  I think my problem is that I'm not getting anything for some of the powered off VMs as well as for some of those without tools installed.

    I found another post that is similar to the GuestOS property I'm looking for at referencing the Get-View summary.config.guestfullname property.  I recognize that is the value entered during VM creation, but should be fine for what I'm looking for. 

    This has led me to another issue that I'm seeing with regard to filters using get-view.  Since that diverges from this original post I'll either create another post or find an already posted solution.



    PS L:\> (get-vm vut-it-*|select Name,PowerState,@{E={$_.guest.osfullname}},@{E={$_.ExtensionData.Guest.toolsstatus}})

    Name                            PowerState $_.guest.osfullname                 $_.ExtensionData.Guest.toolsstatus

    ----                            ---------- -------------------                 ----------------------------------

    VUT-IT-APP001-IPERF-TEST         PoweredOn Ubuntu Linux (32-bit)                                         toolsOld

    VUT-IT-APP003-RHEL7-TEST         PoweredOn Red Hat Enterprise Linux 6 (64-bit)                  toolsNotInstalled

    VUT-IT-APP004-RHEL6-TEST         PoweredOn Red Hat Enterprise Linux 6 (64-bit)                            toolsOk

    VUT-IT-APP007-PowerIQ-TEST       PoweredOn CentOS 4/5/6/7 (64-bit)                                        toolsOk

    VUT-IT-LOG001-Nagios-Log-Server  PoweredOn                                                      toolsNotInstalled