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

 

Print | posted @ Thursday, August 17, 2006 2:30 AM

Comments on this entry:

Gravatar # re: Powershell: Attach Debugger To ASP.NET Worker Process By Name
by Sahil Malik at 8/17/2006 4:28 PM

This is super cool. :)

Might as well create a shortcut key for this macro eh?
  
Comments have been closed on this topic.