VMware Cloud Community
john23
Commander
Commander
Jump to solution

VMware Powercli round function


Hi,

I am trying to use round function in my script. Objective of script is calculate avg CPU an avg Mem at Folder level. I want after decimal, it should print upto level two (10.52) like that.

Its not working Smiley Sad


     $stats1 = Get-Stat -Entity $FolderVMs -Stat "mem.usage.average" -Start $todayMidnight.AddDays(-15) -Finish $todayMidnight.AddDays(-1) -ErrorAction SilentlyContinue | Where-Object {
  $workingDays -contains $_.Timestamp.DayOfWeek -and$_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay }

    

     $TempObject.MemAvg =  [math]::round((($stats1 | Measure-Object -Property value  -Average) ,2).AVERAGE)

-A

Thanks -A Read my blogs: www.openwriteup.com
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The parenthesis are not correct, try like this

$TempObject.MemAvg =  [math]::round(($stats1 | Measure-Object -Property value  -Average | Select -ExpandProperty Average),2)


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The parenthesis are not correct, try like this

$TempObject.MemAvg =  [math]::round(($stats1 | Measure-Object -Property value  -Average | Select -ExpandProperty Average),2)


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

0 Kudos
john23
Commander
Commander
Jump to solution

Thanks LucD.. It solves the purpose Smiley Happy

Thanks -A Read my blogs: www.openwriteup.com
0 Kudos