VMware Cloud Community
Guv
Enthusiast
Enthusiast
Jump to solution

Memory Values from KB to MB

I have attached a script on getting VM performance via using the get-stat command. Its mainly on memory counters.

The script works fine, but I would like the values in MB, instead if KB, as the KB values are too long and dont look presentable in reports. Also I want the values rounded as well as I dont want too many values after the decimal value. I have used the math/round command on one of the counters in the script but I want the values in MB. Is there anyway my script above can be modified to get memory values in MB. Is this possible to do with the math/round command or any other way.

Thanks

0 Kudos
1 Solution

Accepted Solutions
Troy_Clavell
Immortal
Immortal
Jump to solution

what results are you looking for? With that said, I probably am not supplying you the correct code anyway. You may have better luck in the VMware vSphere™ PowerCLI Forum

here's what I get

Name                          : PHX00206
NumCpu                        : 1
MemoryMB                      : 1792
Average Memory Usage MBytes   : 1122747
AVerage Memory Swapin MBytes  :
Average Memory Swapout MBytes :

View solution in original post

0 Kudos
3 Replies
Troy_Clavell
Immortal
Immortal
Jump to solution

I'm no Powershell expert by any means, but I changed a couple lines in your script and it seems to work fine for me

$vm = $args
$businessDays = "Monday","Tuesday","Wednesday","Thursday","Friday"
$dayStart = New-Object DateTime(1,1,1,7,30,0)
$dayEnd = New-Object DateTime(1,1,1,17,30,0) 
$vmguest = @{ N = "operating System" ; E = { ( get-vmguest -VM $_ ).osfullname}}
Get-VM  | where {$_.PowerState -eq "PoweredOn"} | `
	Select name,NumCpu, MemoryMB, 
		@{N="Average Memory Usage MBytes";E={[math]::Round((get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.consumed.average | Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday} | Measure-Object -Property Value -Average).Average)}}, 
                @{N="AVerage Memory Swapin MBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.swapin.average | Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday} | Measure-Object -Property Value -Average).Average}},
                @{N="Average Memory Swapout MBytes";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.swapout.average | Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday} | Measure-Object -Property Value -Average).Average}}

0 Kudos
Guv
Enthusiast
Enthusiast
Jump to solution

THanks for the feedback.

The only change I can see is the change to the Name value of the header from kbytes to mbytes. I cant see any changes to the expression part of the script. Is there something I am missing

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

what results are you looking for? With that said, I probably am not supplying you the correct code anyway. You may have better luck in the VMware vSphere™ PowerCLI Forum

here's what I get

Name                          : PHX00206
NumCpu                        : 1
MemoryMB                      : 1792
Average Memory Usage MBytes   : 1122747
AVerage Memory Swapin MBytes  :
Average Memory Swapout MBytes :

0 Kudos