Skip to main content

Resource Usage

 

 

 

Memory Usage

The code snippet below will work with PowerShell 3.0 and newer

if ([Environment]::Is64BitOperatingSystem) {
  #64 bit logic here
  get-process | Group-Object -Property ProcessName | 
  % {
      [PSCustomObject]@{
          ProcessName = $_.Name
          Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet64 -Sum).Sum / 1MB, 0)
          ProcessCount = $_.Count
      }
  } | sort -desc Mem_MB | Select-Object -First 25
} else {
  #32 bit logic here
  get-process | Group-Object -Property ProcessName | 
  % {
      [PSCustomObject]@{
          ProcessName = $_.Name
          Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet -Sum).Sum / 1MB, 0)
          ProcessCount = $_.Count
      }
  } | sort -desc Mem_MB | Select-Object -First 25
}

The code below will execute on Windows 7 and newer.

if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit") {
  #64 bit logic here
  get-process | Group-Object -Property ProcessName | 
  % {
      [PSCustomObject]@{
          ProcessName = $_.Name
          Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet64 -Sum).Sum / 1MB, 0)
          ProcessCount = $_.Count
      }
  } | sort -desc Mem_MB | Select-Object -First 25
} else {
  #32 bit logic here
  get-process | Group-Object -Property ProcessName | 
  % {
      [PSCustomObject]@{
          ProcessName = $_.Name
          Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet -Sum).Sum / 1MB, 0)
          ProcessCount = $_.Count
      }
  } | sort -desc Mem_MB | Select-Object -First 25
}