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

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
  }
}

 

posted on Wednesday, August 16, 2006 10:30 PM by scott

Comments

Thursday, August 17, 2006 9:28 AM by Sahil Malik

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

This is super cool. :)

Might as well create a shortcut key for this macro eh?
Thursday, August 17, 2006 7:20 PM by Jason Haley

# Interesting Finds: August 17, 2006