Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Stop-ProcessWithTimeoutAndWarning {
- param(
- # name of process to stop
- [Parameter(Mandatory = $True)]
- [string]$Name,
- # timeout (in seconds) to wait before killing process
- [Parameter(Mandatory = $False)]
- [int]$Timeout = 30
- )
- if (Get-Process -Name $Name -ErrorAction SilentlyContinue) {
- Write-Output "detected running instance of '$Name'"
- Write-Output ".. you've got $Timeout seconds to save & close your documents .."
- Start-Sleep -Seconds $Timeout
- Stop-Process -Name $Name -Force
- Write-Output ".. waiting 2 seconds .."
- Start-Sleep -Seconds 2
- } else {
- Write-Output "could not find any running instance of '$Name' ..."
- }
- }
Add Comment
Please, Sign In to add comment