0

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 
       }
Illuminati
  • 555
  • 2
  • 7
  • 34
  • 1
    I will also point out that you don't need that last pipe and that alone may be the problem. – EBGreen Jul 16 '13 at 19:45
  • What exactly are you trying to accomplish? – Kevin_ Jul 16 '13 at 19:50
  • Wanted to find the Memory size of all the systems in the network with computer names provided to them the code above is just a small bit of the code – Illuminati Jul 16 '13 at 20:12
  • Kevin can you please help me in the other thread posted please http://stackoverflow.com/questions/17679674/how-to-store-data-from-foreach-function-in-html-file-in-powershell-and-get-physi?rq=1 – Illuminati Jul 16 '13 at 20:13

3 Answers3

3

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
Kevin_
  • 2,916
  • 3
  • 19
  • 18
1
$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.

eltaco431
  • 740
  • 2
  • 10
  • 24
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
   }

Will solve the problem :D

Illuminati
  • 555
  • 2
  • 7
  • 34