Powershell: Stop Process safely when the process is running or not

$odis = Get-Process OffboardDiagLauncher -ErrorAction SilentlyContinue
if ($odis) {
# Close process safely
  $odis.CloseMainWindow()
# Wait 5 seconds
  Sleep 5
  if (!$odis.HasExited) {
# Force stop process
    $odis | Stop-Process -Force
  }
}
Remove-Variable odis

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *