Pages

Monday, October 7, 2013

PowerShell Script to list Worker Processors and their Application Pool Names with Memory consumption and CPU utilization.


Using the following Power Shell Script you will be able to enumerate worker processors and associated Application Pool Names with details of Memory consumption and CPU Utilization, that will help during investigation and troubleshooting when System Resources are in critical condition. 


The PS Script will list PID (Processor ID), VM (Virtual Memory), PM (Physical Memory), WS (Working Set), CPU utilization, with ‘Application Pool Name’.

$list = get-process w3wp
$lineitems = @()
   foreach($p in $list)
   {
                $linestr = New-Object PSObject
                $filter = "Handle='" + $p.Id + "'"
                $wmip = get-WmiObject Win32_Process -filter $filter
                $cmdline = $wmip.CommandLine
               
                [regex]$pattern="-ap ""(.+)"""
                $PoolNameStr = $pattern.Match($cmdline).Groups[1].Value
                $PoolName = $PoolNameStr.substring(0, $PoolNameStr.IndexOf(""""))

                $linestr | add-member NoteProperty Id  $p.Id
                $linestr | add-member NoteProperty VM $p.VM
                $linestr | add-member NoteProperty PM  $p.PM
                $linestr | add-member NoteProperty WS  $p.WS
                $linestr | add-member NoteProperty CPU  $p.CPU
                $linestr |  add-member NoteProperty "AppPoolName" $PoolName
                $lineitems += $linestr
   }
$lineitems | Format-Table * -AutoSize

Format-Table


Out-GridView

You can also use Grid View parameter which displays data in Grid View.






No comments:

Post a Comment