使用powershell无法获取物理内存信息

发布于 2024-08-05 18:43:05 字数 1268 浏览 8 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-08-12 18:43:05

我认为您对 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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文