I've been putting together a pretty simple script to monitor some aspects of our Terminal Server farm usage and am implementing a section where I check the memory usage on the servers at a given point in time. Here is the particular section that I am using to get that:
<#Modified to troubleshoot this particular section; defined $TermSvr and pipe output directly to
host:#>
$RemoteSvr = "Win10Test"
#Check current Memory Usage and Available Space
$SysMem = Get-WmiObject Win32_OperatingSystem -ComputerName $RemoteSvr
"$RemoteSvr has {0:#.0} GB free space out of {1:#.0} GB total available memory" -f
($SysMem.FreePhysicalMemory/1GB),
($SysMem.TotalVisibleMemorySize/1GB) | Write-Host
This outputs:
Win10Test has **.0** GB free space out of **.0** GB total available memory
But; when I change the ($_.SysMem.TotalVisibleMemorySize/1GB) to ($_.SysMem.TotalVisibleMemorySize/1MB)
It outputs:
Win10Test has 1.1 GB free space out of 3.8 GB total available memory
Which is correct. But I feel like I'm taking crazy pills at this point. Am I missing something simple here to explain why these are only returning the value which translates into MEGABYTES of memory as opposed to the actual GIGABYTES of memory I have on the systems?
I have tried running this script against:
- Windows 8.1
- Windows 10 (Tech Preview)
- Windows Server 2012 R2
Always the same outcome.