VMware Cloud Community
vinnie967
Contributor
Contributor

Need help with PowerCLI to get VM info for each VCenter and output to specific sheet in excel

Hi everyone,

I would like to pull the following info from these example vcenters:

VDCNPRAZ

NACNPRAZ

PLCNPR8T

I would like to have it exported to a excel workbook name 'test.xlsm' and into the sheet name 'vmware'.  I would like to pull the following data from each vCenter and have it in the following example report layed out in the following format. I am new to PowerCLI and I would like to learn how to used it to pull the following data.

VIRTUAL HOSTNAMEPHYSICAL HOSTNAMECLUSTERDATA CENTER NAMEVCENTER NAMEHARDWARE VENDORSERVER MODELOPERATING SYSTEMCPU TYPEVIRTUAL CPUPHYSICAL CPU SOCKETPHYSICAL CORES PER SOCKETSERVER FRAMEVIRTUAL MEMORYPHYSICAL MEMORYSERVER NOTESPHYSICAL HOST SERIAL NUMBER
SLVPR23SUCNPR01DTVT01DATACNTR1VDCNPRAZHPPROLIANT DL360P GEN8WINDOWS 2008 ENTEPRISE EDITIONINTEL(R) XEON(R) CPU E5-2640 0 @ 2.50GHZ226SVERFRM1 65501TEST SERVERMXQ31WW60K
WLVPR45SUCNPR02PRVT01DATACNTR2NACNPRAZHPPROLIANT DL360P GEN8REDHAT LINUX 5 ENTERPRISEINTEL(R) XEON(R) CPU E5-2640 0 @ 2.50GHZ226SVERFRM2 65501WAS SERVERMXQ312360J
PRVPR46172.27.0.200CLSTR1DATACNTR3PLCNPR8THPPROLIANT BL460C G7WINDOWS 2003 ENTEPRISE EDITIONINTEL(R) XEON(R) CPU X5650 @ 2.67GHZ226SVERFRM3 98293ORACLE DB SERVERDXQ312360J

Any help on this would be greatly appreciated.

Thank you,

v

0 Kudos
3 Replies
JohnMcKeown
Enthusiast
Enthusiast



I too was learning to script a few months ago. If you are starting you should start with one liners like: 


http://virtualizeme.net/power-cli-one-liners/


This will get you used to understanding commandlets like Get-VMhost


Also try to break down your query into different parts. Most data manipulation is with CSVs. Although you can export to excel its additional work that you can just do with Excel yourself. 


There are loads of examples of host reports that you can tailor yourself. Here is a good example. https://communities.vmware.com/message/1697364 


$report = @()



Get-VMHost | ForEach-Object {



  $VMHost = $_



  $row = "" | Select-Object -Property `



      VCENTER,ESXName ,Cluster, Datacenter, `



      VMs, VMCount,Vendor, Model, `



      PowerState, ConnectionState, InMaintenanceMode, BootTime, OverallStatus, `



      Version, Build, FullName, CpuModel



  $row.VCENTER = $VMHost.ExtensionData.Client.ServiceUrl.Split('/')[2]



  $row.ESXName = $VMHost.ExtensionData.name



  $row.Cluster = $VMHost.Parent



  $row.Datacenter= (Get-Datacenter -Cluster $VMHost.Parent).Name



  $VMs = ""



  $VMHost | Get-VM | ForEach-Object {$VMs += "$($_.Name),"}



  $row.VMs = $VMs.TrimEnd(",")



  $row.VMCount = @($VMHost | Get-VM).Count



  $row.Vendor = $VMHost.ExtensionData.Summary.Hardware.vendor



  $row.Model = $VMHost.ExtensionData.Summary.Hardware.model



  $row.PowerState = $VMHost.ExtensionData.Summary.runtime.powerstate



  $row.ConnectionState = $VMHost.ExtensionData.Summary.runtime.connectionState



  $row.InMaintenanceMode = $VMHost.ExtensionData.Summary.runtime.inMaintenanceMode



  $row.BootTime = $VMHost.ExtensionData.Summary.runtime.bootTime



  $row.OverallStatus = $VMHost.ExtensionData.Summary.overallStatus



  $row.Version = $VMHost.ExtensionData.Config.Product.version



  $row.Build = $VMHost.ExtensionData.Config.Product.build



  $row.FullName = $VMHost.ExtensionData.Config.Product.fullName



  $row.CpuModel = $VMHost.ExtensionData.Summary.Hardware.CpuModel



  $report += $row



}



$report | export-csv "c:\test.csv" -noTypeInformation-UseCulture




Copy it into powercli and it will output what you are looking for and a bit more. I did not change the sorting because you can do that yourself in excel or If you look at the properties above and the corresponding lines of code you can arrange to your liking.

0 Kudos
meistermn
Expert
Expert


Maybe http://www.robware.net/  is faster for what you need?

0 Kudos
meistermn
Expert
Expert



Here is a goog a example for rvtools and excel pivot.

http://www.maentz.net/pensieve/yfq0uvj7vp1ybfj5wm8h7e4b9t3gk6

0 Kudos