PowerShell, Quick Tips, Scripting
comments 6

Quick PowerShell Tip: Get Process commandline information

This morning I answered a quetion on TechNet Windows PowerShell forum regarding retrieving a process commandline arguments. You cannot do this using Get-Process cmdlet. I thought I should share it here as well.

Let us look at an example. I started a PowerShell process by passing a .PS1 script name to it. For the sake of demo, this script just sleeps for a long time. I used Start-> Run option to run the following commandline  

PowerShell.exe C:\scripts\Testravi.ps1   

Get-Process has no commandline property to see the arguments I just sent to PowerShell.exe 



However, Win32_Process WMI class provides the commandline arguments information. This calss has a property called CommandLine. So, we can use Get-WMIObject cmdlet to see the commandline arguments passed to PowerShell.exe. To do this,  

This will filter the process information for the PowerShell process and output the commandline property value.   

Get Process using WMI

Get Process using WMI


Filed under: PowerShell, Quick Tips, Scripting


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.