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
VM | PowerState | OverallStatus | VMHost | ProvisionedSpace | UsedSpace | CPUUsage | MemUsage | GuestOS | MemorySize | CPUCount | Uptime | IPAddress | DNSName | Notes | Cluster | Version |
VUT-IT-LOG001-Nagios-Log-Server | PoweredOn | green | midvm42.local | 169.15 | 67.24 | 29 | 0 | | 65536 | 1 | 3012334 | | | | Linux Cluster | v7 |
VMLXTEST-RHEL-Test | PoweredOn | green | midvm53.local | 50.18 | 22.40 | 37 | 1.99 | Red Hat Enterprise Linux 6 (64-bit) | 2048 | 2 | 10266288 | 10.8.1.245 | vmlxtest.local | | | v8 |
VWP-IT-APP046-Solarwinds-Polling | PoweredOn | green | midvm35.local | 182.21 | 68.41 | 3763 | 4.99 | Microsoft Windows Server 2012 (64-bit) | 32768 | 4 | 4386118 | 10.8.11.124 | VWP-IT-APP046.local | | Production Cluster | v9 |