Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Math or string wrong in script help!

$
0
0

The script below is suppose to query the recommended page file size and compare it to the current page file size. 

If I set the page file size it always says it is wrong because of the math in this statement

(([int64]$RAM * 1.5)).tostring("0")

without the .tostring("0") I get 5968.5

With the .tostring("0") I get 5969

Why is it rounding?

 

$TotalPageFileSize = 0

 

"Page File Information:" 

    write-host

$RAM = Get-WmiObject Win32_OperatingSystem | select TotalVisibleMemorySize

$RAM = ([int64]$RAM.TotalVisibleMemorySize / 1kb).tostring("00")

#$RoundedRAM = ([Decimal]$RAM.TotalVisibleMemorySize / (1024*1024)).tostring("0.00")

$RecommendedPageFileSize = (([int64]$RAM * 1.5)).tostring("0")

 

"     Installed RAM: " + ($RAM/1024).tostring("0.00") + " GB" 

"     Recommended page file size: " + $RecommendedPageFileSize + " MB" 

 

$TotalPageFileSize = Get-wmiobject Win32_PageFile | Measure-Object -property FileSize -Sum |Select-Object Sum

 

$PageFileInfo = Get-wmiobject Win32_PageFile | Select-Object Drive, FileSize, InitialSize, MaximumSize

 

"     Total Page File Size: " + ($TotalPageFileSize.SUM /(1024*1024)) + " MB"  

    write-host

    If ($TotalPageFileSize.SUM /(1024*1024) -ne $RecommendedPageFileSize) 

    {write-host "     The total page file size does not match the recommended size." -foreground yellow -background black

    write-host "     Please review the total page file size on the server and adjust accordingly." -foreground yellow -background black}


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images