views:

206

answers:

1

I am having trouble getting physical memory information from windows management objects using powershell. The columns are generated in the excel spreadsheet yet there is no data found in the Winmgmt object.

$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
+1  A: 

I think your call to Get-WmiObject is incorrect. The following seems to work:

$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
}
Grant Wagner