Powershell: Attach Debugger To ASP.NET Worker Process By Name

Thursday, August 17, 2006

For those who don't like the "Attach To Process" dialog box, just pass the application pool name to this Powershell function:

function debug-wp([string]$name)
{
  if([String]::IsNullOrEmpty($name))
  {
    throw "Usage: debug-wp -Name "<appPoolName>"
  }

  $wplist = get-wmiobject Win32_Process -f "Name='w3wp.exe'"
  foreach($wp in $wplist)
  {
    if($wp.CommandLine -match "-ap `"(.+)`"")
    {
      if($name -eq $matches[1])
      {
        & vsjitdebugger.exe -p $wp.ProcessID
        break
      }
    }
  }

  if($name -ne $matches[1])
  {
    write-host "Could not find AppPool" $name
  }
}

 


Comments
Sahil Malik Thursday, August 17, 2006
This is super cool. :)

Might as well create a shortcut key for this macro eh?
Comments are closed.

My Pluralsight Courses

K.Scott Allen OdeToCode by K. Scott Allen
What JavaScript Developers Should Know About ECMAScript 2015
The Podcast!