< Back

Stop-PRTGScript

Sun Jan 19, 2020 5:46 pm

NAME Stop-PRTGScript



SYNOPSIS





SYNTAX

Stop-PRTGScript [[-ErrorRecord] <ErrorRecord>] [[-ExitCode] <Int32>] [<CommonParameters>]





DESCRIPTION

Shortcut function for converting an exception into the PRTG JSON Error Format, outputting it, then exiting the

script





PARAMETERS

-ErrorRecord <ErrorRecord>

The error record to provide info from. Typically this is passed via $PSItem in either a catch or trap context



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ExitCode <Int32>

The exitcode to use. Defaults to 2 (System Error). Common PRTG Codes are 0=OK,1=WARNING,2=System Error (e.g. a

network/socket error),3=Protocol Error (e.g. web server returns a 404),Content Error (e.g. a web page does not

contain a required word). NOTE: These are not handled by PRTG for Advanced Sensors



Required? false

Position? 2

Default value 2

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$ErrorActionPreference = 'Stop'



trap {Stop-PRTGScript $PSItem}



Put this at the top of your script to return a meaningful error for any Powershell exceptions that may occur in

your script









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>try {



throw "This didn't work!"

}

catch {Stop-PRTGScript $PSItem}

Only do handling for a very specific amount of code











RELATED LINKS