0

get-wmiobject -query "从 Win32_LogicalMemoryConfiguration 中选择 TotalPhysicalMemory" -computer COMPUTERNAME >>output.csv

get-wmiobject -query "从 Win32_LogicalMemoryConfiguration 中选择 TotalPageFileSpace" -computer COMPUTERNAME >>output.csv

我正在尝试使用如下输出来完成此脚本:

Computer        Physical Memory      Virtual Memory
server1         4096mb               8000mb
server2         2048mb               4000mb
4

2 回答 2

1

有什么阻止你做这样的事情吗?

gwmi -query "Select TotalPhysicalMemory,TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer $COMPUTERNAME |
  select @{Name='Computer', Expression=$COMPUTERNAME},
         @{Name='Physical Memory', Expression=$_.TotalPhysicalMemory},
         @{Name='Virtual Memory', Expression=$_.TotalPageFileSize} |
  Export-Csv

(未经测试,因为 Get-WmiOject 在这里不知道 Win32_LogicalMemoryConfiguration 类。但可能有效。)

于 2010-05-12T06:43:53.093 回答
0

Win32_LogicalMemoryConfiguration 似乎已过时。我认为这个函数会得到你想要的信息:

function Get-MemoryInfo
{
    Process
    {
        Get-WmiObject Win32_OperatingSystem -ComputerName $_ |
        % {
            New-Object PSObject |
            Add-Member NoteProperty Computer $_.CSName -PassThru |
            Add-Member NoteProperty VirtualMemoryMB ([int]($_.TotalVirtualMemorySize / 1KB)) -PassThru
        } |
        % {
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Computer
            $_ | Add-Member NoteProperty PhysicalMemoryMB ([int]($cs.TotalPhysicalMemory / 1MB)) -PassThru
        }
    }
}

您可以将计算机列表通过管道传输到 Get-MemoryInfo。如果需要 csv 文件,然后将输出通过管道传输到 Export-Csv。

于 2010-05-12T14:48:53.457 回答