【问题标题】:How to get free physical memory of remote computer using PowerShell如何使用 PowerShell 获取远程计算机的可用物理内存
【发布时间】:2012-08-28 08:43:21
【问题描述】:

我有这个:

(Get-WMIObject Win32_logicaldisk -computername computer).TotalPhysicalMemory

获取安装在远程计算机上的物理内存大小。 我如何获得那台计算机的空闲内存?

我试过了

(Get-WMIObject Win32_logicaldisk -computername computer).FreePhysicalMemory

和其他一些变体,但没有效果。是否有一些可能的“过滤器”列表?

【问题讨论】:

    标签: windows powershell memory-management powershell-remoting


    【解决方案1】:

    我相信你想要Win32_OperatingSystem 而不是Win32_logicaldisk

    【讨论】:

      【解决方案2】:

      当您想查看对象的所有属性时,将其通过管道发送到Format-List *

      Get-WmiObject Win32_LogicalDisk | format-list *
      Get-WmiObject Win32_OperatingSystem | fl *
      

      或者,如果您正在寻找特定的属性,您可以使用通配符搜索

      Get-WmiObject Win32_OperatingSystem | fl *free*
      

      正如 Aquinas 所说,您需要 Win32_OperatingSystem 类,FreePhysicalMemory 属性。 Win32_LogicalDisk 跟踪硬盘,而不是 RAM。

      【讨论】:

      • 如果他实际上是指磁盘空间,属性将是SizeFreeSpace
      【解决方案3】:

      您也可以尝试Get-Counter cmdlet:

      (Get-Counter -Counter "\Memory\Available MBytes" -ComputerName computer).CounterSamples[0].CookedValue
      

      【讨论】:

        【解决方案4】:

        所以把其他答案放在一起:

        get-ciminstance Win32_OperatingSystem | % FreePhysicalMemory
        

        远程:

        invoke-command computer { get-ciminstance Win32_OperatingSystem | % FreePhysicalMemory } 
        

        【讨论】:

        • 我相信这真的应该是Get-CimInstance Win32_OperatingSystemGet-WmiObject 自 PowerShell 3.x 起已弃用,自 PowerShell 6.x 起已删除。
        【解决方案5】:

        本地机器的可用内存(远程使用-computername foo):

        (Get-WMIObject Win32_OperatingSystem).FreePhysicalMemory  # in KB
        
        19793740
        
        (Get-WMIObject Win32_OperatingSystem).FreePhysicalMemory / 1MB  # in GB
        
        18.8592491149902
        

        除以 1MB 得到 GB 可能看起来很奇怪,但原始数字只是以 KB 为单位给出的。结果其实和写* 1KB / 1GB(也可以用)没什么区别。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-10-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-08
          • 1970-01-01
          相关资源
          最近更新 更多