VMware Cloud Community
jfierberg
Contributor
Contributor
Jump to solution

Rounding out CPU Utilization

I want to round off the cpu utilization percentage that is generated from the powershell script below. How do I do this?

$cpu=@{ name=”CPU”;`

expression = { `

($_ | get-stat –stat “cpu.usage.average” `

–maxsamples 12 | measure-object –average –property value).average } `

}

get-vmhost | select name,$cpu `

| sort –property CPU –descending | ConvertTo-HTML -Property Name,"CPU" `

-title "VMware Host CPU Utilization" | Format-Table Name,[math]::Round($cpu) -Auto | Out-File "C:\cpu.html"

0 Kudos
1 Solution

Accepted Solutions
kjb007
Immortal
Immortal
Jump to solution

Hopefully this looks ok in the post, else I will post as a text file. Basically, at the start of the expression line, add '[int]'

($_ | get-stat –stat “cpu.usage.average” `

Ok, it does not look good in the post, see the attachment.

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB

View solution in original post

0 Kudos
3 Replies
kjb007
Immortal
Immortal
Jump to solution

Here's a simpler method, just cast it into an int, it will be rounded. $cpu

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
jfierberg
Contributor
Contributor
Jump to solution

Where in the code do I insert the int?

0 Kudos
kjb007
Immortal
Immortal
Jump to solution

Hopefully this looks ok in the post, else I will post as a text file. Basically, at the start of the expression line, add '[int]'

($_ | get-stat –stat “cpu.usage.average” `

Ok, it does not look good in the post, see the attachment.

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos