2009-09-25 63 views
0

我无法使用PowerShell获取来自Windows管理对象的物理内存信息。这些列在Excel电子表格中生成,但Winmgmt对象中没有找到任何数据。无法使用powershell获取物理内存信息

 
$strComputer = “.” 

$Excel = New-Object -Com Excel.Application 
$Excel.visible = $True 
$Excel = $Excel.Workbooks.Add() 

$Sheet = $Excel.WorkSheets.Item(1) 
$Sheet.Cells.Item(1,2) = “Bank Label” 
$Sheet.Cells.Item(1,3) = “Capacity” 
$Sheet.Cells.Item(1,4) = “Caption” 
$Sheet.Cells.Item(1,5) = “Data Width” 
$Sheet.Cells.Item(1,6) = “Description” 
$Sheet.Cells.Item(1,7) = “Device Locator” 
$Sheet.Cells.Item(1,8) = "Form Factor" 

$WorkBook = $Sheet.UsedRange 
$WorkBook.Interior.ColorIndex = 8 
$WorkBook.Font.ColorIndex = 11 
$WorkBook.Font.Bold = $True 

$intRow = 2 
$colItems = get-wmiobject -class “Win32_PhysicalMemory” -namespace “root CIMV2" -computername $strComputer 

foreach ($objItem in $colItems) { 
$Sheet.Cells.Item($intRow,1)= $strComputer 
$Sheet.Cells.Item($intRow,2) = $objItem.BankLabel 
$Sheet.Cells.Item($intRow,3) = $objItem.Capacity 
$Sheet.Cells.Item($intRow,4) = $objItem.Caption 
$Sheet.Cells.Item($intRow,5) = $objItem.DataWidth 
$Sheet.Cells.Item($intRow,6) = $objItem.Description 
$Sheet.Cells.Item($intRow,7) = $objItem.DeviceLocator 
$Sheet.Cells.Item($intRow,8) = $objItem.FormFactor 

$intRow = $intRow + 1 

} 


$WorkBook.EntireColumn.AutoFit() 
Clear 

回答

2

我认为您致电Get-WmiObject的说法不正确。以下似乎工作:

$strComputer = “.” 

$colItems = Get-WmiObject Win32_PhysicalMemory -namespace root\CIMV2 -computername $strComputer 
#$colItems = get-wmiobject -class “Win32_PhysicalMemory” -namespace “root CIMV2" -computername $strComputer 

foreach ($objItem in $colItems) { 
    Write-Host "BankLabel " $objItem.BankLabel 
    Write-Host "Capacity  " $objItem.Capacity 
    Write-Host "Caption  " $objItem.Caption 
    Write-Host "DataWidth " $objItem.DataWidth 
    Write-Host "Description " $objItem.Description 
    Write-Host "DeviceLocator" $objItem.DeviceLocator 
    Write-Host "FormFactor " $objItem.FormFactor 
}