获取RAM信息 - Powershell

时间:2016-06-10 20:33:13

标签: powershell export-to-csv get-wmiobject

我有一个PC列表,我需要获得物理内存和可用内存插槽的数量。我在一个文本文件中有一个PC列表,我正在使用" get-content"小命令。这就是我所拥有的:

Get-WmiObject -Class Win32_PhysicalMemory -ComputerName (Get-Content "C:\TextFile.txt") | ForEach-Object {[math]::truncate($_.capacity / 1GB)}

运行此选项时,仅显示Memory total。我的两个问题是:

1)如何让PC名称显示在相应的数字旁边?

2)我如何添加可用的总内存插槽?

谢谢!

2 个答案:

答案 0 :(得分:1)

DeviceLocator告诉您插槽。

实施例

$memoryBySlot = Get-CimInstance -Class Win32_PhysicalMemory | Foreach-Object { 
    [PSCustomObject] @{
        CapacityGB = $_.Capacity /1GB
        DeviceLocator = $_.DeviceLocator
        ComputerName = $env:COMPUTERNAME
    }
}
$memoryBySlot | Out-String

$memoryBySlot | Measure-Object -Property CapacityGB -Sum | select count, sum, property

结果

CapacityGB DeviceLocator ComputerName
---------- ------------- ------------
        16 DIMM1         MYMACHINE
        16 DIMM2         MYMACHINE
        16 DIMM3         MYMACHINE
        16 DIMM4         MYMACHINE


Count Sum Property
----- --- --------
    4  64 CapacityGB

答案 1 :(得分:0)

你可以尝试这样的事情:

Get-Content "C:\TextFile.txt" | % {$a = (Get-CimInstance -ClassName Win32_PhysicalMemory -ComputerName $_ | Measure-Object -Sum -Property Capacity).Sum / (1024*1024*1024); [PSCUStOMOBJECT]@{"Computer"=$_;"MEM"=$a}} |export-csv 'file.csv'