Last active
November 21, 2021 16:14
-
-
Save nuvious/9defe383a90ed67c07de200b4823d266 to your computer and use it in GitHub Desktop.
A powershell script that kills a named process after a specified sleep interval.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
A script which kills a process by name (ex: vlc.exe) after a specified | |
delay. | |
.DESCRIPTION | |
SleepKill allows a user to define a delay before killing off a process. | |
An example usage is to kill a video program that's playing a playlist for | |
someone going to sleep where they may not want it on all night and need | |
their computer to remain on for other reasons (say an alarm clock app). | |
.PARAMETER Duration | |
The duration in seconds to wait before killing the process. | |
.PARAMETER Target | |
The target executable name; ex vlc, msedge, etc. | |
.EXAMPLE | |
C:\PS> .\SleepKill.ps1 -target vlc -duration 3600 | |
.NOTES | |
Author: David Cheeseman | |
Date: November 21, 2021 | |
#> | |
param( | |
[int]$Duration, | |
[string]$Target | |
) | |
if (! $Duration -or ! $Target){ | |
Write-Host "Duration and target are require parameter." | |
Write-Host "Run Get-Help SleepKill.ps1 for more information." | |
exit 1 | |
} | |
Write-Host "Sleeping $Duration seconds and then killing all $Target instances." | |
Start-Sleep $Duration | |
Stop-Process -Name $Target -Force -Erroraction 'silentlycontinue' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment