我一直在编写一个非常简单的脚本来监视我们的terminal服务器场的使用情况的一些方面,并实施一个部分,我在一个给定的时间点检查服务器上的内存使用情况。 以下是我正在使用的特定部分:
<#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
这输出:
Win10Test has **.0** GB free space out of **.0** GB total available memory
但; 当($ _。SysMem.TotalVisibleMemorySize / 1GB )更改为($ _。SysMem.TotalVisibleMemorySize / 1MB )时,
它输出:
Win10Test has 1.1 GB free space out of 3.8 GB total available memory
哪个是对的。 但是我觉得我现在正在服用疯狂的药丸。 我是否在这里错过了一些简单的东西来解释为什么这些只是返回转换为内存的MEGABYTES的值,而不是我在系统上的实际内存的GIGABYTES?
我曾尝试运行此脚本:
总是一样的结果。
根据MSDN上的Win32_OperatingSystem类 :
TotalVisibleMemorySize
数据types:uint64
访问types:只读
操作系统可用的物理内存总量(以千字节为单位)。
FreePhysicalMemory当然也是如此。
在PowerShell中除以1GB等于除以1073741824 (或1024*1024*1024 )。 因此,内存的数量需要以字节表示,以便除以1GB,以GB为单位返回一定数量的RAM。
由于TotalVisibleMemorySize是千字节,所以可以通过以下方式转换为GB:
TotalVisibleMemorySize/1MB
要么
TotalVisibleMemorySize*1024/1GB