Search code examples
powershellshellterminalexitpowershell-4.0

How to terminate a terminal session in a ps1 script


How can I terminate a terminal/PowerShell window from a .ps1 script? I would like it to work the way exit in command line works, but when I put that in a PowerShell script it only terminates the script.


Solution

  • Environment.Exit() will terminate the whole process:

    # replace 0 with a non-0 error code if you want to indicate some sort of failure
    [Environment]::Exit(0)