Can I use PowerShell 1.0 to list processes along with their PID and commands?

EDIT by OP:. My question suggests that PowerShell was the best tool for this job. There is an easier way to achieve my goal. A friend just told me about: iisapp.vbs . It displays exactly the information I need without requiring PowerShell.


I work with dozens of ASP.NET sites working locally, and when I want to debug a specific website with the name foo.site.com, for example, I follow these steps:

  • Launch Process Explorer (from SysInternals) and find which w3wp.exe was launched using foo.site.com on the command line.

  • Note the process identifier (PID) of this process w3wp.exe.

  • Visual Studio attaches to this process identifier.

Is there a way to write a PowerShell script that will print the PID and command line arguments for each w3wp.exe process running on my computer?

When I run get-process w3wp, I get:

> get-process w3wp Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 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: (

Thanks!

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

+4
source share
3 answers

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

He has to do the trick. It seems strange to me that PowerShell does not provide default command line information. Note. I tested it only in powershell 2.0, but since it uses wmi, it should work in 1.0.

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

+12
source

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 does not work because $ _. StartInfo.Argments is always null. WMI works, however.

 get-wmiobject win32_process -filter "name='w3wp.exe'" | select-object processid, commandline 
+2
source

This should work:

get-process | Format table identifier, path

0
source

Source: https://habr.com/ru/post/1286700/


All Articles