Guest User

Untitled

a guest
Nov 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function Stop-ProcessWithTimeoutAndWarning {
  2. param(
  3. # name of process to stop
  4. [Parameter(Mandatory = $True)]
  5. [string]$Name,
  6. # timeout (in seconds) to wait before killing process
  7. [Parameter(Mandatory = $False)]
  8. [int]$Timeout = 30
  9. )
  10.  
  11. if (Get-Process -Name $Name -ErrorAction SilentlyContinue) {
  12. Write-Output "detected running instance of '$Name'"
  13. Write-Output ".. you've got $Timeout seconds to save & close your documents .."
  14. Start-Sleep -Seconds $Timeout
  15. Stop-Process -Name $Name -Force
  16. Write-Output ".. waiting 2 seconds .."
  17. Start-Sleep -Seconds 2
  18. } else {
  19. Write-Output "could not find any running instance of '$Name' ..."
  20. }
  21. }
Add Comment
Please, Sign In to add comment