Handy and short Powershell script that is meant to be used for testing purposes, if you are writing your own function, you might wanna get insight which command will produce terminating errors, so you can put them into appropriate try and catch blocks.

In my opinion, it can be very useful in case you are writing the enterprise-class script, where you want to handle all of the errors as good as possible.

Always remember to put your command under the quotes.

 

PowerShell
Edit|Remove
<#
.SYNOPSIS
Simple function used for error testing, it will discover if your command is producing terminating error.

.DESCRIPTION
Simple function used for error testing, it will discover if your command is producing terminating error.

.EXAMPLE
Find-TerminatingError -YourCommand "Get-help get-item" # This one will produce no errors.
Find-TerminatingError -YourCommand "Execute-NonExistentCommand" # This one wil produce terminating error.

#>
Function Find-TerminatingError {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$True,
        Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]$YourCommand
    )
    Process {
        $ErrorActionPreference = "SilentlyContinue"
        trap {
            Write-Host "Caught terminating error." -ForegroundColor Red
            Continue
        }
        Write-Host "Executing $YourCommand"
        Invoke-Expression $YourCommand
    }
}