Skip to content

Instantly share code, notes, and snippets.

@Groostav
Last active October 9, 2020 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Groostav/15ed0b2bad3d8169901ff19d08cd7c4b to your computer and use it in GitHub Desktop.
Save Groostav/15ed0b2bad3d8169901ff19d08cd7c4b to your computer and use it in GitHub Desktop.
what is powershells Stop-Process doing
Write-Host "Host Version:" $Host.Version
Try
{
Write-Host "before!"
Stop-Process 123456789 -EA Stop
Write-Host "after!"
}
Catch
{
Write-Host "caught red handed!"
}
Finally
{
Write-Host "finally!"
}
<#
C:\Users\geoff\Desktop> .\Testing-Try-Catch.ps1
Host Version: 5.1.19041.1
before!
caught red handed!
finally!
#>
Write-Host "Host Version:" $Host.Version
Try
{
Write-Host "before!"
Stop-Process 123456789
Write-Host "after!"
}
Catch
{
Write-Host "caught red handed!"
}
Finally
{
Write-Host "finally!"
}
<#
C:\Users\geoff\Desktop> .\Testing-Try-Catch.ps1
Host Version: 5.1.19041.1
before!
Stop-Process : Cannot find a process with the process identifier 123456789.
At C:\Users\geoff\Desktop\Testing-Try-Catch.ps1:6 char:5
+ Stop-Process 123456789
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (123456789:Int32) [Stop-Process], ProcessCommandException
+ FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.StopProcessCommand
after!
#>
finally!
@Groostav
Copy link
Author

Groostav commented Oct 9, 2020

what a pain in the butt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment