加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

powershell – Win32_OperatingSystem.FreePhysicalMemory和$_.T

发布时间:2020-12-13 23:44:13 所属栏目:Windows 来源:网络整理
导读:我一直在整理一个非常简单的脚本来监控我们的终端服务器场使用的某些方面,并实现了一个部分,我在一个给定时间点检查服务器上的内存使用情况.以下是我使用的特定部分: #Modified to troubleshoot this particular section; defined $TermSvr and pipe output
我一直在整理一个非常简单的脚本来监控我们的终端服务器场使用的某些方面,并实现了一个部分,我在一个给定时间点检查服务器上的内存使用情况.以下是我使用的特定部分:
<#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内存?

我试过运行这个脚本:

> Windows 8.1
> Windows 10(技术预览版)
> Windows Server 2012 R2

总是一样的结果.

根据 Win32_OperatingSystem class on MSDN:

TotalVisibleMemorySize
Data type: uint64
Access type: Read-only
Total amount,in kilobytes,of physical memory available to the operating system.

当然,FreePhysicalMemory也是如此.

在PowerShell中除以1GB相当于除以1073741824(或1024 * 1024 * 1024).因此,需要以字节为单位表示内存量,以便除以1GB以返回GB的RAM量.

由于TotalVisibleMemorySize以千字节为单位,因此您可以通过以下方式转换为GB:

TotalVisibleMemorySize/1MB

要么

TotalVisibleMemorySize*1024/1GB

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读