Tuesday, March 12, 2013

Powershell Working with Running Processes

# List all the running processes:
Get-Process
# List all the running processes where processname is ‘java’:
Get-Process | where { $_.ProcessName –eq ‘java’ }
# Get all the running processes where processname is ‘java’ and foreach over them calling kill on each of them:
Get-Process | where { $_.ProcessName –eq ‘java’ } | foreach { kill $_ }
# With shorthand aliases (ps is for get-process, ? Is for “where”, % is for “foreach”):
ps | ? { $_.ProcessName –eq ‘java’ } | % { kill $_ }
view raw gistfile1.ps1 hosted with ❤ by GitHub