Terminating a process
A process can be terminated with the returned object's Kill() method, for example because the process in question is hanging:
PS:\> (get-process excel).kill()
Selecting specific processes
Property value
By combining
get-process and
where-object in a
pipeline, it's possible to select processes by criterias applied on their properties:
get-process | where-object name -match app
Select processes whose process memory (pm) is greater than 250 mega bytes:
get-process | where-object pm -gt 250mb
-id / (Process identifier)
get-process -id $PID | select-object startTime, totalProcessorTime, userProcessorTime, virtualMemorySize, workingSet
Select my session's processes
get-process | where-object {
$_.SI -eq ([System.Diagnostics.Process]::GetCurrentProcess().SessionId) -and
#
# Exclude some well known proceses:
#
$_.processName -notin
'csrss',
'dllhost',
'dwm',
'explorer',
'RuntimeBroker',
'SecurityHealthSystray',
'ShellExperienceHost',
'sihost',
'svchost',
'taskhostw',
'unsecapp',
'winlogon',
# WSL related
'wsl', 'wslrelay', 'wslhost'
}
TODO: Is TextInputHost a well-known process as well?
Property aliases
The objects returned by get-process have some property aliases.
PS: 6 C:\Users\rene> get-process | get-member -memberType aliasProperty, scriptProperty
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Handles AliasProperty Handles = Handlecount
Name AliasProperty Name = ProcessName
NPM AliasProperty NPM = NonpagedSystemMemorySize64
PM AliasProperty PM = PagedMemorySize64
SI AliasProperty SI = SessionId
VM AliasProperty VM = VirtualMemorySize64
WS AliasProperty WS = WorkingSet64
Company ScriptProperty System.Object Company {get=$this.Mainmodule.FileVersionInfo.CompanyName;}
CPU ScriptProperty System.Object CPU {get=$this.TotalProcessorTime.TotalSeconds;}
Description ScriptProperty System.Object Description {get=$this.Mainmodule.FileVersionInfo.FileDescription;}
FileVersion ScriptProperty System.Object FileVersion {get=$this.Mainmodule.FileVersionInfo.FileVersion;}
Path ScriptProperty System.Object Path {get=$this.Mainmodule.FileName;}
Product ScriptProperty System.Object Product {get=$this.Mainmodule.FileVersionInfo.ProductName;}
ProductVersion ScriptProperty System.Object ProductVersion {get=$this.Mainmodule.FileVersionInfo.ProductVersion;}