Question

Below is the code snippet i tried but having an error because of it can anyone helpme in editing this one

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

La solution

You already had it. You just added too much.

Gwmi win32_PhysicalMemory | Measure-Object -Property Capacity -Sum

And if you wanted to show only the sum then:

Gwmi win32_physcialmemory | measure-object -property Capacity -sum | select sum

Autres conseils

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

Your code works fine. You just have an extra pipe at the end of your gwmi cmdlet.

   $colItems4 = Get-WMIObject -class Win32_PhysicalMemory  -computername $strComputer
      $colItems5=$colItems4 | Measure-Object -Property capacity -Sum 
      foreach ($objItem4 in $colItems5)
   {

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

Will solve the problem :D

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top