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