e.g: if I run notepad.exe c:\autoexec.bat
,
How can I get c:\autoexec.bat
in Get-Process notepad
in PowerShell?
Or how can I get c:\autoexec.bat
in Process.GetProcessesByName("notepad");
in C#?
Description. The Get-Help cmdlet displays information about PowerShell concepts and commands, including cmdlets, functions, Common Information Model (CIM) commands, workflows, providers, aliases, and scripts. To get help for a PowerShell cmdlet, type Get-Help followed by the cmdlet name, such as: Get-Help Get-Process .
To get started, open up your PowerShell console and run Get-Process . Notice, that Get-Process returns the running process information, as shown below. The output format is identical for the Windows and Linux operating systems. Using the Get-Process cmdlet on Windows to display local processes.
The command to open Command Prompt from Windows PowerShell is exactly the same as the command to open Command Prompt from Command Prompt. In Windows PowerShell, just type start cmd.exe and press Enter.
To find the PID of a process, type Get-Process . Indicates that the UserName value of the Process object is returned with results of the command. Specifies one or more process objects. Enter a variable that contains the objects, or type a command or expression that gets the objects.
This answer is excellent, however for futureproofing and to do future you a favor, Unless you're using pretty old powershell (in which case I recommend an update!) Get-WMIObject has been superseded by Get-CimInstance Hey Scripting Guy reference
Try this
$process = "notepad.exe" Get-CimInstance Win32_Process -Filter "name = '$process'" | select CommandLine
In PowerShell you can get the command line of a process via WMI:
$process = "notepad.exe" Get-WmiObject Win32_Process -Filter "name = '$process'" | Select-Object CommandLine
Note that you need admin privileges to be able to access that information about processes running in the context of another user. As a normal user it's only visible to you for processes running in your own context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With