KillProcesses.ps1 711 B

123456789101112131415161718192021222324252627282930
  1. $ErrorActionPreference = 'Continue'
  2. function _kill($processName) {
  3. try {
  4. # Redirect stderr to stdout to avoid big red blocks of output in Azure Pipeline logging
  5. # when there are no instances of the process
  6. & cmd /c "taskkill /T /F /IM ${processName} 2>&1"
  7. } catch {
  8. Write-Host "Failed to kill ${processName}: $_"
  9. }
  10. }
  11. _kill dotnet.exe
  12. _kill testhost.exe
  13. _kill iisexpress.exe
  14. _kill iisexpresstray.exe
  15. _kill w3wp.exe
  16. _kill msbuild.exe
  17. _kill vbcscompiler.exe
  18. _kill git.exe
  19. _kill vctip.exe
  20. _kill chrome.exe
  21. _kill h2spec.exe
  22. _kill WerFault.exe
  23. if (Get-Command iisreset -ErrorAction ignore) {
  24. iisreset /restart
  25. }
  26. Stop-Service w3svc -NoWait -ErrorAction Ignore
  27. exit 0