Is there an equivalent "... || die" in powershell?
Most commands support the general -ErrorAction parameter. Specifying -ErrorAction Stop usually stops the script on error. See Get-Help about_CommonParameters .
By default, -ErrorAction is Continue . You can change the default setting by changing the value of $ErrorActionPreference . See Get-Help about_Preference_Variables .
If verbosity is indeed a problem, -ErrorAction has the alias -ea .
Another way to implement the constructor ...|| die ...|| die in PowerShell without the need to add huge try-catch constructs will the $? automatic variable be used $? .
From Get-Help about_Automatic_variables :
$? Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed. Just add the following after each critical statement:
if(-not $?){ # Call Write-EventLog or write $Error[0] to an xml or txt file if you like Exit(1) }