Invoke-ADTFunctionErrorHandler
SYNOPSIS
Handles errors within ADT functions by logging and optionally passing through the error.
SYNTAX
None (Default)
Invoke-ADTFunctionErrorHandler -Cmdlet <PSCmdlet> -SessionState <SessionState> -ErrorRecord <ErrorRecord>
[-LogMessage <String>] [<CommonParameters>]
ResolveErrorProperties
Invoke-ADTFunctionErrorHandler -Cmdlet <PSCmdlet> -SessionState <SessionState> -ErrorRecord <ErrorRecord>
[-LogMessage <String>] -ResolveErrorProperties <String[]> [<CommonParameters>]
AdditionalResolveErrorProperties
Invoke-ADTFunctionErrorHandler -Cmdlet <PSCmdlet> -SessionState <SessionState> -ErrorRecord <ErrorRecord>
[-LogMessage <String>] -AdditionalResolveErrorProperties <String[]> [<CommonParameters>]
DisableErrorResolving
Invoke-ADTFunctionErrorHandler -Cmdlet <PSCmdlet> -SessionState <SessionState> -ErrorRecord <ErrorRecord>
[-LogMessage <String>] [-DisableErrorResolving] [<CommonParameters>]
DESCRIPTION
This function handles errors within ADT functions by logging the error message and optionally passing through the error record. It recovers the true ErrorActionPreference set by the caller and sets it within the function. If a log message is provided, it appends the resolved error record to the log message. Depending on the ErrorActionPreference, it either throws a terminating error or writes a non-terminating error.
EXAMPLES
EXAMPLE 1
Invoke-ADTFunctionErrorHandler -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState -ErrorRecord $_
Handles the error within the calling cmdlet and logs it.
EXAMPLE 2
Invoke-ADTFunctionErrorHandler -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState -ErrorRecord $_ -LogMessage "An error occurred" -DisableErrorResolving
Handles the error within the calling cmdlet, logs a custom message without resolving the error record, and logs it.
PARAMETERS
-Cmdlet
The cmdlet that is calling this function.
Type: PSCmdlet
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-SessionState
The session state of the calling cmdlet.
Type: SessionState
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ErrorRecord
The error record to handle.
Type: ErrorRecord
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-LogMessage
The error message to write to the active ADTSession's log file.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ResolveErrorProperties
If specified, the specific ErrorRecord properties to print during resolution.
Type: String[]
Parameter Sets: ResolveErrorProperties
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
-AdditionalResolveErrorProperties
If specified, a list of additional ErrorRecord properties to print during resolution.
Type: String[]
Parameter Sets: AdditionalResolveErrorProperties
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DisableErrorResolving
If specified, the function will not append the resolved error record to the log message.
Type: SwitchParameter
Parameter Sets: DisableErrorResolving
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
None
You cannot pipe objects to this function.
OUTPUTS
None
This function does not return any output.
NOTES
An active ADT session is NOT required to use this function.
Tags: psadt
Website: https://psappdeploytoolkit.com
Copyright: (C) 2025 PSAppDeployToolkit Team (Sean Lillis, Dan Cunningham, Muhammad Mashwani, Mitch Richters, Dan Gough).
License: https://opensource.org/license/lgpl-3-0
RELATED LINKS
https://psappdeploytoolkit.com/docs/reference/functions/Invoke-ADTFunctionErrorHandler