Here’s a PowerShell script that allows you to monitor processes on the local or a remote PC. It’s based on the Get-Process cmdlet. It loops every secon, compares changes in the process list and displays them nicely on the screen. It shows a green line when a new process runs and a yellow line when a process quits.

Have fun! And let me know what you think in the comments.ProcessMonitor.ps1

 

Function ProcessMonitor {

<#
.SYNOPSIS
Displays changes in the process list on this or a remote PC.
.DESCRIPTION
Great for monitoring logon/startup scripts, batch jobs, software installations, etc...
Version 1.2, created by Dimitri Koens
.EXAMPLE
ProcessMonitor
Compares changes in the process list every second on the local computer.
.EXAMPLE
ProcessMonitor -Interval 30
Compares changes in the process list for every 30 seconds.
.EXAMPLE
ProcessMonitor -Computername ServerB
Compares changes in the process list on server B. Requires RPC.
#>

param([int]$Interval=1, [string]$Computername='.')

Write-Host "ProcessMonitor (interrupt with Ctrl-C)" -ForegroundColor Cyan

$a = Get-Process -ComputerName $Computername
Do {
  Start-Sleep $Interval
  $b = Get-Process -ComputerName $Computername
  Compare-Object $a $b -Property id -passthru | foreach {
    $msg = "{0:hh:mm:ss} {1,5} pid {2,6:N0}MB vm {3,5:N0}MB ws  {4}  {5}" -f (get-date) , $_.id, ($_.vm/1MB), ($_.ws/1MB), $_.name, $_.path
    if ($_.sideIndicator -eq "=>") { Write-Host $msg -foregroundcolor green  }   # new process running
    if ($_.sideIndicator -eq "<=") { Write-Host $msg -foregroundcolor yellow }   # existing process stopped
  } # foreach
  $a = $b
} while (1 -eq $true)
} # function

ProcessMonitor

Tags: