Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Remove All but Most Recent PowerShell job

Posted on April 21, 2014

I like sending little PowerShell tweet tips, but this one is a bit too long for Twitter. Here is a one-liner to remove all but the most recent job result for each job name.

get-job | group Name | foreach { $_.group | sort PSEndTime -descending | Select -skip 1 | remove-job -whatif}

This assumes you have no jobs running and that you have multiple results for each job name which you might if you are running scheduled PowerShell jobs. In fact, I will be talking about scheduled jobs at the PowerShell Summit next week.

Share this:

  • Print (Opens in new window) Print

Like this:

Like Loading…

Related

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d