Take the 2-minute tour ×

EDIT by OP: My question presupposed that PowerShell was the best tool for this job. There is a simpler way of achieving my goal. A friend just told me about: iisapp.vbs. It displays exactly the info I need without requiring PowerShell.

I'm working with dozens of ASP.NET websites running locally and when I want to debug a particular website named, for example, foo.site.com I go through the following steps:

  1. Run Process Explorer (from SysInternals) and find which w3wp.exe was started with foo.site.com on its command line.

  2. Note the Process ID (PID) of that w3wp.exe process.

  3. In Visual Studio attach to that process ID.

Is there a way to write a PowerShell script that will print the PID and Command Line Arguments of every w3wp.exe process running on my computer?

When I run get-process w3wp I get:

> get-process w3wp

    688      28    44060      64576   226     2.75    196 w3wp
    750      26    48328      68936   225     3.38   1640 w3wp
    989      36    54596      83844   246     4.92   1660 w3wp
    921      33    54344      80576   270     4.24   5624 w3wp
    773      27    48808      72448   244     2.75   5992 w3wp

No Command Line information :(


EDIT: I am looking for the command line arguments that were passed to w3wp.

share|improve this question
There is also an IIS7 snap-in which adds a number of interesting cmdlets for managing IIS. learn.iis.net/page.aspx/447/… –  Brian Reiter Jun 25 '09 at 1:49

3 Answers 3

up vote 11 down vote accepted

gwmi win32_process -filter "name='w3wp.exe'" | select name,processId,commandLine

It should do the trick. I find it weird that powershell doesn't provide command line information by default. Note : I've only tested it in powershell 2.0, but as it use wmi, it should work in 1.0.

EDIT : the final version used by Tim Stewart (to avoid display problem, see comment) :
gwmi win32_process -filter "name='powershell.exe'" | format-table -autosize name,processId,commandLine

share|improve this answer
SuperBloup, that worked! I was disappointed by the layout that PowerShell 1.0 did. PowerShell truncated the command line even though the output only took up half the screen. I found that piping everything to ft -autosize allowed me to see the entire command line. Thanks! –  Tim Stewart Jun 24 '09 at 18:20
As for Powershell not natively giving command-line information by default: blogs.msdn.com/oldnewthing/archive/2009/02/23/9440784.aspx –  Joey Jun 24 '09 at 19:02

My first instinct was to use get-process and look at the startinfo property:

get-process w3wp | select-object id, path, @{Name="Args";Expression = {$_.StartInfo.Arguments}}

Unfortunately, this doesn't work because $_.StartInfo.Argments is always null. WMI works, though.

get-wmiobject win32_process -filter "name='w3wp.exe'" | select-object processid, commandline
share|improve this answer
Brian, thanks for your answer. Replacing: get-wmio[jb]ect with get-wmio[bj]ect was necessary to get the second command to work. –  Tim Stewart Jun 24 '09 at 19:37
Tim, I fixed the transposed letters. Too-fast typing. FWIW in case it was not clear "gwmi" is a standard alias for the "Get-WmiObject" cmdlet and "select" is a standard alias for "Select-Object" –  Brian Reiter Jun 24 '09 at 22:17

This should work:

get-process | format-table Id,Path

share|improve this answer
Robert, thank you for your answer. I apologize if my question was unclear. I'm looking for the command line (including arguments) that the process was started with. –  Tim Stewart Jun 24 '09 at 17:59
Sorry, too eager to answer I guess. Need to read the question twice before posting :) –  Robert Wilczynski Jun 24 '09 at 18:19

Your Answer


