Created
March 20, 2019 10:47
-
-
Save mwallner/75cd7f2352f8e175b39529a575fd8959 to your computer and use it in GitHub Desktop.
get 'youngest' process with some filter possibilites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $False)] | |
[int]$NumberOfProcesses = 1, | |
[Parameter(Mandatory = $False)] | |
[switch]$IncludeMicrosoftProcesses, | |
[Parameter(Mandatory = $False)] | |
[switch]$RequirePath, | |
[Parameter(Mandatory = $False)] | |
[string[]]$IgnoredProcesses | |
) | |
$ErrorActionPreference = "Stop" | |
$procs = if (-Not $IncludeMicrosoftProcesses) { | |
Get-Process | Where-Object {$_.company -notmatch 'microsoft'} | |
} | |
else { | |
Get-Process | |
} | |
if ($IgnoredProcesses) { | |
$procs = $procs | Where-Object {$IgnoredProcesses -notcontains $_.Name} | |
} | |
if ($RequirePath) { | |
$procs = $procs | Where-Object {$_.path} | |
} | |
Write-Output ($procs | Select-Object ID, Name, Path, StartTime, @{Name = "RunTime"; Expression = {(Get-Date) - $_.StartTime}}, WS, VM, Company ` | |
| Sort-Object StartTime -descending ` | |
| Select-Object -first $NumberOfProcesses) |
Author
mwallner
commented
Mar 20, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment