Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / Managing Windows Processes with PowerShell

January 19, 2022 PowerShellWindows 10Windows Server 2016

Managing Windows Processes with PowerShell

PowerShell has a lot of features to manage processes on a local or a remote computer. Using PowerShell, you can get a list of running processes, suspend a hung-up process, find a process by a windows title, run a new process in a hidden or interactive mode, etc.

You can display the list of available process management cmdlets in Windows 10 as follows:

Get-Command –Noun Process

Manage System Processes Using Windows PowerShell

  • Get-Process – get a list of running Windows processes;
  • Start-Process – start a process/program;
  • Stop-Process – forcibly stop (kill) the process;
  • Debug-Process – debug a process;
  • Wait-Process – wait till the process ends.

Contents:
  • Get-Process: Getting a List of Running Processes
  • Start-Process, Stop-Process: How to Start or Stop Processes with PowerShell
  • Manage Processes on a Remote Computer Using PowerShell

Get-Process: Getting a List of Running Processes

The Get-Process cmdlet displays a list of processes running on a local computer.

How to find running processes with Get-Process PowerShell cmdlet?

By default, these properties of running processes are displayed:

  • Handles – the number of input-output file descriptors (handles) opened by this process;
  • NPM(K) – is a non-paged memory (non-paged pool). This is the size of the process data (in KB) that is never paged on disk;
  • PM(K) – the size of the process memory that may be paged;
  • WS(K) – the size of physical memory (in KB) used by the process (Working Set);
  • CPU(s) – a CPU time used by the process (time on all CPUs is counted);
  • ID – unique process identifier;
  • SI (Session ID) – is the process session ID (0 means running for all sessions, 1- running for the first logged on user, 2 — running for the second logged on user, etc.);
  • ProcessName

To list all properties of multiple processes:

Get-Process cmd,excel,notep* | Format-List *

You can display the specific process properties only, for example, a name (ProcessName), a start time (StartTime), a process window title (MainWindowTitle), an executable file name (Path) and a developer name (Company):

Get-Process winword, notep* | Select-Object ProcessName, StartTime, MainWindowTitle, Path, Company|ft

get-process executable path and MainWindowTitle

To display a list of running user processes with GUI (background and system processes will not be displayed):

Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle

powershell: get-process filtering

Using the IncludeUserName option, you can display a user name (owner) who has started the process:

Get-Process -Name winword -IncludeUserName

Using Where-Object, you can select processes according to some criteria. For example, let’s display all processes using over 300 MB of RAM, sort them in the descending order by the memory usage and show the memory size in MB instead of KB:

Get-Process| where-object {$_.WorkingSet -GT 300000*1024}|select processname,@{l="Used RAM(MB)"; e={$_.workingset / 1mb}} |sort "Used RAM(MB)" –Descending

powershell: find top running processes by highest memory usage

As we told earlier, the Get-Process cmdlet in the CPU parameter contains the processor time used by the specific process in seconds. To display the percentage of CPU used by processes (similar to the Task Manager), use this function:

function Get-CPUUsagePercent
{
$CPUPercent = @{
Name = 'CPUPercent'
Expression = {
$TotalSec = (New-TimeSpan -Start $_.StartTime).TotalSeconds
[Math]::Round( ($_.CPU * 100 / $TotalSec), 2)
}
}
Get-Process | Select-Object -Property Name, $CPUPercent, Description | Sort-Object -Property CPUPercent -Descending | Select-Object -First 20
}
Get-CPUUsagePercent

Listing processes by CPU usage percentage in powershell

To find hung processes (which are not responding), run the following command:

Get-Process | where-object {$_.Responding -eq $false}

Start-Process, Stop-Process: How to Start or Stop Processes with PowerShell

To start a new process using PowerShell, this command is used:

Start-Process -FilePath notepad

If there is no executable file in the $env:path environment variable, specify the full path to the file:

Start-Process -FilePath 'C:\distr\app.exe'

You can run a program and pass arguments to it:

Start-Process -FilePath ping -ArgumentList "-n 10 10.1.56.21"

Using the WindowStyle option, you can set the process window start mode (normal, minimized, maximized, hidden). For example, to run a program in a maximized window and wait till the process is over, run this command:

Start-Process -FilePath tracert -ArgumentList "10.1.56.21" –wait -windowstyle Maximized

Using Stop-Process cmdlet, you can stop any process. For instance, to close all running notepad processes:

Stop-Process -Name notepad

By default, you are not prompted to confirm killing a process. All processes that meet the specified criteria will be stopped. To be able to confirm stopping processes, add the –Confirm option:

Stop-Process -Name notepad.exe -Confirm

Stop-Process: how to confirm before stopping the process in PowerShell?

Also, you can kill a process as follows:

(Get-Process -Name cmd).Kill()

From PowerShell, you can force stop all apps that are not responding to Windows Process Manager:

Get-Process | where-object {$_.Responding -eq $false}| Stop-Process

Using PowerShell, you can automatically restart a hung or closed process.

Manage Processes on a Remote Computer Using PowerShell

You can use the ComputerName option of the Get-Process cmdlet in order to manage processes on remote computers (WinRM must be enabled and configured).

Get-Process -ComputerName srv01, srv02, srv03| Format-Table -Property ProcessName, ID, MachineName

We deal with the built-in Get-Process features to manage processes on remote computers. PowerShell Remoting features available in Invoke-Command and Enter-PSSession cmdlets are not covered here.

If you want to kill a process on a remote computer, note that the Stop-Process cmdlet doesn’t have the –ComputerName parameter. To stop a process on a remote computer, you can use the following PowerShell code:

$RemoteProcess = Get-Process -Name cmd -ComputerName srv01
Stop-Process -InputObject $RemoteProcess

1 comment
1
Facebook Twitter Google + Pinterest
previous post
Dumping User Passwords from Windows Memory with Mimikatz
next post
Time-Based (Temporary) Group Membership in Active Directory

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

1 comment

Tom April 19, 2023 - 6:21 am

Change the process priority:
Get-WmiObject Win32_process -filter ‘name = “ProcessName.exe”‘ | foreach-object { $_.SetPriority(PriorityLevelID) }
or
wmic process where name=”ProcessName” CALL setpriority “PriorityLevelID”

idle: 64
below normal: 16384
normal: 32
above normal: 32768
high priority: 128
real time: 256

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Configuring Port Forwarding in Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Hide Installed Programs in Windows 10 and 11
  • Configuring SFTP (SSH FTP) Server on Windows
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top