使用powershell无法获取物理内存信息
我在使用 powershell 从 Windows 管理对象获取物理内存信息时遇到问题。这些列是在 Excel 电子表格中生成的,但在 Winmgmt 对象中找不到数据。
$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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您对
Get-WmiObject
的调用不正确。以下似乎有效:I think your call to
Get-WmiObject
is incorrect. The following seems to work: