CHAPTER 3
To list every process, as shown in previous examples, use the Get-Process command. Just by invoking the command in the shell, it will internally call a foreach loop to show you every active process in your computer with some properties and show it as a formatted table.
Get-Process |

Get Process Result
There are some parameters and options you might want to use to list all active processes according to requirements you may have. In the following example, you should replace the MyMachineName string value with a valid machine name. You can check your machine name by running the hostname command in your shell or command-line tool.
#Execute Get-Process on a remote computer. Get-Process -ComputerName "MyMachineName" #Get specific attributes. Get-Process | select Id,Name #Condition the process you want to list (Chrome processes only). Get-Process | ?{$_.Name -like "*chrome"} |
Another thing you can do after retrieving all running processes is to process them to extract information. An example of that is evaluating CPU usage for all Google Chrome processes on your machine.
#How much CPU do all chrome processes consume? $sumCpuUsage=0 write "All Chrome Processes:" Get-Process -ComputerName "MyMachineName” |` ?{$_.Name -like "*chrome"} | %{ $id=$_.Id $cpu = $_.CPU "Process:$id CPU: $cpu" $sumCpuUsage+=$_.CPU } write "Total CPU: $sumCpuUsage" |
After listing all your processes, you might identify a process that you wish to analyze in particular; to do so, you must get its ID and then call it using the attribute –Id of the Get-Process command.
Get-Process -Id 11372 |
To stop a process, you need to use the command Stop-Process followed by the attribute ID, which is mandatory in this situation. To optimize your command, you might get that process by ID and then pipe it to the stop command. In the following example, you find all instances of Internet Explorer running in your machine and then stop them.
#Using the get by Id concept Get-Process -ProcessName “iexplore” | Stop-Process |
Launching a process in PowerShell is easy thanks to the Start-Process command. This command not only starts the process but also returns the process object itself, which can then be examined or manipulated. This command starts one or more processes on the local computer, either if you set as a parameter the path to the executable file, or if you set as a path, one to a file. In this case, PowerShell will launch the default program to open the file’s extension.
<# EXAMPLE 1: Start a program #> #Path from file. $path = "C:\temp\Paint.NET.lnk" #Start new process. $process = Start-Process $path #Get process id started. $process.Id <# EXAMPLE 2: Start a file with the default program to open it #> #Path from file. $path = "C:\temp\ListaUsers.csv" #Start new process. $process = Start-Process $path #Get process id started. $process.Id |