0

下面是我尝试过的代码片段,但由于它有一个错误,任何人都可以帮助我编辑这个

  $colItems4 = Get-WMIObject -class Win32_PhysicalMemory | Measure-Object -Property capacity -Sum | 
       foreach ($objItem4 in $colItems4 )
       {
             write-host "Total Physical Ram : " $objItem4.Sum 
       }
4

3 回答 3

3

你已经有了。你加的太多了。

Gwmi win32_PhysicalMemory | Measure-Object -Property Capacity -Sum

如果您只想显示总和,那么:

Gwmi win32_physcialmemory | measure-object -property Capacity -sum | select sum
于 2013-07-16T20:03:29.060 回答
1
$colItems4 = Get-WMIObject -class Win32_PhysicalMemory | Measure-Object -Property capacity -Sum
foreach ($objItem4 in $colItems4 )
{
     write-host "Total Physical Ram : " $objItem4.Sum 
}

您的代码工作正常。您在 gwmi cmdlet 的末尾有一个额外的管道。

于 2013-07-16T19:52:43.463 回答
0
   $colItems4 = Get-WMIObject -class Win32_PhysicalMemory  -computername $strComputer
      $colItems5=$colItems4 | Measure-Object -Property capacity -Sum 
      foreach ($objItem4 in $colItems5)
   {

      write-host "Memory :  " $colItems5.Sum
   }

将解决问题:D

于 2013-07-16T19:51:03.960 回答