Can I use PowerShell 1.0 to list processes along with their PIDs and Command Lines?

Question:

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:

No Command Line information 🙁

Thanks!

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

Answer:

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

Source:

Can I use PowerShell 1.0 to list processes along with their PIDs and Command Lines? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply