VMware

This Question is Answered

1 "helpful" answer available (6 pts)
4 Replies Last post: Sep 9, 2009 9:28 AM by a2alpha  

calculating values in a powershell script for host information - summary.hardware and summary.quickstats posted: Sep 9, 2009 8:33 AM

Click to view a2alpha's profile Expert 315 posts since
Apr 20, 2008

Hi,

I am running the below script but want to modify it so that I can add the Maximum CPU available and % CPU used statistics into the table by way of a calculation, I am just struggling to get the syntax right as you will see highlighted below.

I would really appreciate some help.

Thanks,

Dan

$Report = @()
$ESXHosts = Get-VMHost | Sort Name | Get-View
ForEach ($ESXHost in $ESXHosts)
{
$ReportObj = "" | Select Name, "VMotion Enabled", "Connection State", "Overall CPU", "Max CPU", "% CPU Used"
$ReportObj.Name = $ESXHost.Name
$ReportObj."VMotion Enabled" = $ESXHost.summary.config.vmotionenabled
$ReportObj."Connection State" = $ESXHost.summary.runtime.connectionstate
$ReportObj."Overall CPU" = $ESXHost.summary.quickStats.overallCpuUsage
$ReportObj."Max CPU" = *(($ESXHost.summary.NumCpuCores*$ESXHost.summary.NumCpuPkgs*$ESXHost.summary.CpuMhz))*
$ReportObj."% CPU Used" = *(($ESXHost.summary.quickStats.overallCpuUsage)/(($ESXHost.summary.NumCpuCores*$ESXHost.summary.NumCpuPkgs*$ESXHost.summary.CpuMhz)))*
$Report += $ReportObj
}
$Report | ConvertTo-Html -title "Advanced Host Information" -body "<H4>Advanced Host Information</H4>" | Out-File -Append $filelocation

Click to view Zsoldier's profile Hot Shot 90 posts since
Sep 22, 2006
Depending on how you want your formula's to be calculated, you'll need to make use of parenthesis and you need to go one level deeper. For instance:

$ReportObj."Max CPU" = "($ESXHost.summary.hardware.NumCpuCores)*($ESXHost.summary.hardware.NumCpuPkgs))"


This would multply numcpucores by numcpuPkgs.

Click to view Zsoldier's profile Hot Shot 90 posts since
Sep 22, 2006

Sorry, take out the quotes.

$ReportObj."Max CPU" = ($ESXHost.summary.hardware.NumCpuCores)*($ESXHost.summary.hardware.CpuMhz))

VMware Beta Programs

Want to be Considered for Future Beta Programs?

Learn More

VMware Developer

Download SDKs, APIs, videos,
training, and more in the Developer community.

Learn More

Developer
Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld
Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

Only VMware ... Delivers Nexus 1000V

Ensure consistent, policy-based network capabilities to virtual machines across your data center.

Learn More

Communities