0

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 Answer 1

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.