Skip to main content
Applied syntax highlighting ; Grammatical corrections
Source Link
JW0914
  • 8.3k
  • 7
  • 31
  • 50
function htopish {
  Param (
    [Parameter(Position=1)] [Alias("l")]
    [int]$TotalList=24,
    [Parameter(Position=2)] [Alias("r")]
    [int]$Invertal=1
  )
  Begin {}
  Process {
    While ($true) {
      $CounterSamples = Get-Counter '\Process(*)\ID Process','\Process(*)\% Processor Time','\Process(*)\Working Set' | Select-Object -Expand CounterSamples
      Clear-Host
      $CounterSamples | Group-Object { Split-Path $_.Path } | Where-Object {$_.Group[1].InstanceName -notmatch "^Idle|_Total|System$"} | Sort-Object -Property {$_.Group[1].CookedValue} -Descending | Select-Object -First $TotalList | Format-Table @{Name="ProcessId";Expression={$_.Group[0].CookedValue}},@{Name="ProcessorUsage";Expression={[System.Math]::Round($_.Group[1].CookedValue/100/$env:NUMBER_OF_PROCESSORS,4)}},@{Name="ProcessName";Expression={$_.Group[1].InstanceName}},@{Name="WorkingSet";Expression={[System.Math]::Round($_.Group[2].CookedValue/1MB,4)}}
      Sleep -Seconds $Invertal
    }
  }
  End {}
}
function htopish {
  Param (
  [Parameter(Position=1)] [Alias("l")]
  [int]$TotalList=24,
  [Parameter(Position=2)] [Alias("r")]
  [int]$Invertal=1
  )
  Begin {}
  Process {
    While ($true) {
      $CounterSamples = Get-Counter '\Process(*)\ID Process','\Process(*)\% Processor Time','\Process(*)\Working Set' | Select-Object -Expand CounterSamples
      Clear-Host
      $CounterSamples | Group-Object { Split-Path $_.Path } | Where-Object {$_.Group[1].InstanceName -notmatch "^Idle|_Total|System$"} | Sort-Object -Property {$_.Group[1].CookedValue} -Descending | Select-Object -First $TotalList | Format-Table @{Name="ProcessId";Expression={$_.Group[0].CookedValue}},@{Name="ProcessorUsage";Expression={[System.Math]::Round($_.Group[1].CookedValue/100/$env:NUMBER_OF_PROCESSORS,4)}},@{Name="ProcessName";Expression={$_.Group[1].InstanceName}},@{Name="WorkingSet";Expression={[System.Math]::Round($_.Group[2].CookedValue/1MB,4)}}
    Sleep -Seconds $Invertal
  }
  }
  End {}
}

The function relies on the Get-Counter samples and will output the ProcessId,ProcessName,ProcessorUsage and WorkingSet. This counter sample could further be enhanced to include User,CommandLine in the output but I haven't worked out yet a performant way to do it.

  • Function relies on the Get-Counter samples and will output the ProcessId, ProcessName, ProcessorUsage, and WorkingSet.
  • This counter sample could be further enhanced to include User and CommandLine in the output, but I haven't yet worked out a performant way to do so.
function htopish {
  Param (
    [Parameter(Position=1)] [Alias("l")]
    [int]$TotalList=24,
    [Parameter(Position=2)] [Alias("r")]
    [int]$Invertal=1
  )
  Begin {}
  Process {
    While ($true) {
      $CounterSamples = Get-Counter '\Process(*)\ID Process','\Process(*)\% Processor Time','\Process(*)\Working Set' | Select-Object -Expand CounterSamples
      Clear-Host
      $CounterSamples | Group-Object { Split-Path $_.Path } | Where-Object {$_.Group[1].InstanceName -notmatch "^Idle|_Total|System$"} | Sort-Object -Property {$_.Group[1].CookedValue} -Descending | Select-Object -First $TotalList | Format-Table @{Name="ProcessId";Expression={$_.Group[0].CookedValue}},@{Name="ProcessorUsage";Expression={[System.Math]::Round($_.Group[1].CookedValue/100/$env:NUMBER_OF_PROCESSORS,4)}},@{Name="ProcessName";Expression={$_.Group[1].InstanceName}},@{Name="WorkingSet";Expression={[System.Math]::Round($_.Group[2].CookedValue/1MB,4)}}
      Sleep -Seconds $Invertal
    }
  }
  End {}
}

The function relies on the Get-Counter samples and will output the ProcessId,ProcessName,ProcessorUsage and WorkingSet. This counter sample could further be enhanced to include User,CommandLine in the output but I haven't worked out yet a performant way to do it.

function htopish {
  Param (
  [Parameter(Position=1)] [Alias("l")]
  [int]$TotalList=24,
  [Parameter(Position=2)] [Alias("r")]
  [int]$Invertal=1
  )
  Begin {}
  Process {
    While ($true) {
      $CounterSamples = Get-Counter '\Process(*)\ID Process','\Process(*)\% Processor Time','\Process(*)\Working Set' | Select-Object -Expand CounterSamples
      Clear-Host
      $CounterSamples | Group-Object { Split-Path $_.Path } | Where-Object {$_.Group[1].InstanceName -notmatch "^Idle|_Total|System$"} | Sort-Object -Property {$_.Group[1].CookedValue} -Descending | Select-Object -First $TotalList | Format-Table @{Name="ProcessId";Expression={$_.Group[0].CookedValue}},@{Name="ProcessorUsage";Expression={[System.Math]::Round($_.Group[1].CookedValue/100/$env:NUMBER_OF_PROCESSORS,4)}},@{Name="ProcessName";Expression={$_.Group[1].InstanceName}},@{Name="WorkingSet";Expression={[System.Math]::Round($_.Group[2].CookedValue/1MB,4)}}
    Sleep -Seconds $Invertal
  }
  }
  End {}
}
  • Function relies on the Get-Counter samples and will output the ProcessId, ProcessName, ProcessorUsage, and WorkingSet.
  • This counter sample could be further enhanced to include User and CommandLine in the output, but I haven't yet worked out a performant way to do so.
Source Link
Hames
  • 271
  • 2
  • 3

This may also do the trick:

function htopish {
  Param (
    [Parameter(Position=1)] [Alias("l")]
    [int]$TotalList=24,
    [Parameter(Position=2)] [Alias("r")]
    [int]$Invertal=1
  )
  Begin {}
  Process {
    While ($true) {
      $CounterSamples = Get-Counter '\Process(*)\ID Process','\Process(*)\% Processor Time','\Process(*)\Working Set' | Select-Object -Expand CounterSamples
      Clear-Host
      $CounterSamples | Group-Object { Split-Path $_.Path } | Where-Object {$_.Group[1].InstanceName -notmatch "^Idle|_Total|System$"} | Sort-Object -Property {$_.Group[1].CookedValue} -Descending | Select-Object -First $TotalList | Format-Table @{Name="ProcessId";Expression={$_.Group[0].CookedValue}},@{Name="ProcessorUsage";Expression={[System.Math]::Round($_.Group[1].CookedValue/100/$env:NUMBER_OF_PROCESSORS,4)}},@{Name="ProcessName";Expression={$_.Group[1].InstanceName}},@{Name="WorkingSet";Expression={[System.Math]::Round($_.Group[2].CookedValue/1MB,4)}}
      Sleep -Seconds $Invertal
    }
  }
  End {}
}

The function relies on the Get-Counter samples and will output the ProcessId,ProcessName,ProcessorUsage and WorkingSet. This counter sample could further be enhanced to include User,CommandLine in the output but I haven't worked out yet a performant way to do it.