VMware Cloud Community
griese
Enthusiast
Enthusiast
Jump to solution

Creating equivalent vSphere Client report with PowerCLI

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.

Thanks,

Troy

&{get-vm |where-object {$_.VMHost.Parent -notlike "Excluded_Cluster_Here*"}|%{
$VMID=Get-View ($_.id)
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

               

VMPowerStateOverallStatusVMHostProvisionedSpaceUsedSpaceCPUUsageMemUsageGuestOSMemorySizeCPUCountUptimeIPAddressDNSNameNotesClusterVersion
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
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Oops, you are right, I messed up there.

It's

$vm.Guest.OSFullName

or

$vm.ExtensionData.Guest.GuestFullName

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).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try changing that line to

GuestOS = $_.ExtensionData.Guest.OSFullName

Any other properties you are looking for?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
griese
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, you are right, I messed up there.

It's

$vm.Guest.OSFullName

or

$vm.ExtensionData.Guest.GuestFullName

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).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
griese
Enthusiast
Enthusiast
Jump to solution

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 https://communities.vmware.com/thread/243948 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.

Thanks!

Troy

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

Reply
0 Kudos