0

I am looking for a way to kill processes matching a certain name if (and only if) their uptime is 4hours+

I plan to then schedule the script every hour or so to detect and kill processes matching my criterias.

I have been googling around for solutions with batch, powershell and vbscripts but did not find anything matching my needs. Any help will be apreciated!

user3535795
  • 53
  • 2
  • 6
  • You can definitely do this with Powershell, but I doubt anyone here will actually write the code for you. Start off by Googling 'powershell process uptime' and work from there – codebox Oct 21 '14 at 12:05
  • A good place to start, http://stackoverflow.com/questions/26408395/cmd-powershell-sql-server-is-there-any-way-to-see-how-long-a-windows-service-ha – evilSnobu Oct 21 '14 at 20:48

1 Answers1

1

Sorted:

Get-Process -name process_name_goes_here | ForEach-Object {If((New-TimeSpan -Start (get-process -Id $_.Id).StartTime).Hours -ge 4){Stop-Process $_.Id -force}}
user3535795
  • 53
  • 2
  • 6