Monday, December 04, 2006


Todays script is a oneliner that sums up the memory consumption of alle running processes (or rather all visible running processes). It also demonstrates the use of ";" as a line separator

$a = get-process; foreach ($i in $a) {$sum = $sum + $i.workingset}; $sum / 1mb

1 comment:

Jeffrey Snover said...

BTW - you can pipe to foreach and it can take 3 scriptblocks. One gets called before any object, the middle one gets called for each object, the last one gets called after all objects are processed. Thus you can do this:
PS> gps |foreach {$sum=0} {$sum += $_.workingset} {[int]($sum/1mb)

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:
Visit the Windows PowerShell ScriptCenter at: