For those of you who love the top command in Linux…
function Get-Top{
#######################################
##Get-Top
##
##Written By: John Glasgow
#######################################
<#
.SYNTAX
Get-Top [-delay interval] [-pid pid_number]
.SYNOPSIS
Emulates the top command from Linux/Unix.
.EXAMPLE
To set delay of 5 seconds.
Get-Top -delay 5
.EXAMPLE
To watch a particular process.
Get-Top -pid 4408
#>
$delay = 2
$proc = -1
for($i = 0; $i -lt $args.Count; $i += 1){
if( $args[$i] -ilike “-d*” ){
$i++
$delay = $args[$i]
}
if( $args[$i] -ilike “-p*” ){
$i++
$proc = $args[$i]
}
if( $args[$i] -ilike “-q*” ){
$i++
$delay = 0
}
}
while ($true){
Clear-Host
if($proc -gt 0){Get-Process | Sort-Object -Descending cpu | Where-Object{ $_.Id -eq $proc } | Format-Table}
else{Get-Process | Sort-Object -Descending cpu | Select-Object -First 20 | Format-Table}
Start-Sleep -Seconds $delay
}
}
Set-Alias top Get-Top
Like this:
Like Loading...