Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用powershell获取物理内存信息_Powershell_Powershell 1.0 - Fatal编程技术网

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

无法使用powershell获取物理内存信息,powershell,powershell-1.0,Powershell,Powershell 1.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) =

使用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 $strComputer=“” $Excel=新对象-Com Excel.Application $Excel.visible=$True $Excel=$Excel.Workbooks.Add() $Sheet=$Excel.WorkSheets.Item(1) $Sheet.Cells.Item(1,2)=“银行标签” $Sheet.Cells.项目(1,3)=“容量” $Sheet.Cells.Item(1,4)=“标题” $Sheet.Cells.Item(1,5)=“数据宽度” $Sheet.Cells.Item(1,6)=“Description” $Sheet.Cells.Item(1,7)=“设备定位器” $Sheet.Cells.项目(1,8)=“形状系数” $WorkBook=$Sheet.UsedRange $WorkBook.Interior.ColorIndex=8 $WorkBook.Font.ColorIndex=11 $WorkBook.Font.Bold=$True $intRow=2 $colItems=get wmiobject-类“Win32_PhysicalMemory”-命名空间“根CIMV2”-计算机名$strComputer foreach($colitem中的objItem){ $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.entireclumn.AutoFit() 清楚的
我认为您对
获取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
}