Latest Process Activity

by Oct 5, 2011

To find out whether a computer is idling for a long time or actually doing something, here is a function that returns the last process that was recently started, including the time in minutes and days it has been running and its description:

function Get-LastProcessActivity {
  $proc = Get-Process | 
            Sort-Object StartTime  -ea 0 -desc | 
            Select-Object -First 1
  $return = 1 | Select-Object Minutes, Days, Name, Description
  $timespan = New-TimeSpan $proc.StartTime
  $return.Days = $timespan.Days
  $return.Minutes = [Math]::Floor($timespan.TotalMinutes)
  $return.Name = $proc.Name
  $return.Description = $proc.Description

Twitter This Tip!
ReTweet this Tip!