0 votes

Hi there,

i've a custom command with multiple powershell scripts (for clearance reasons).

image.png

If for example the frist script produces an error i Write an Error but the next scripts are still beeing executed.

Is there a way that I can stop further scripts/actions or complete stop the custom command execution when an error will be produced?

I havn't tried with an simple exit 1; I only Write-Errors on issues.

Kind regards, Constantin

by (190 points)

1 Answer

0 votes
by (292k points)
selected by
Best answer

Hello Constantin,

To achieve the desired you can use try catch blocks to handle script terminating errors and use the $Context.Cancel method in the catch blocks. If used in a script executed in a custom command or scheduled task, the method will cancel the command/ task execution. However, if used in a business rule or in a custom command executed by a business rules, the Cancel method will cancel the initial operation that caused execution of the script. For example, if the script is executed in a business rule triggering Before creating a user, the Cancel method will cancel the user creation.

0

Thanks i exactly searched the $Context.Cancel command :)

Related questions

0 votes
1 answer

Hello, I'm trying to execute a custom command through a Powershell script, but I'm struggling to pass multiple values to an AD Object Picker parameter. ... , $NULL, $NULL, 0) $obj.ExecuteCustomCommand($command.CommandID, $commandArguments) Thanks in advance!

asked Nov 24, 2021 by KelseaIT (320 points)
0 votes
1 answer

Are PowerShell commands supposed to show up in the programming interface after adding the module to the Adaxes server? I've installed modules and they don't show.

asked Aug 18, 2020 by ComputerHabit (790 points)
0 votes
1 answer

Hi Is there any possibility to add groups to "Operations" Panel, especially custom commands, in the WebGUI on the user like we can ... Custom Commands Offboarding Offboarding Initiation Offboarding Initiation Fasttrack Notifications Update Mobile Contract

asked Jul 30, 2021 by m.car (80 points)
0 votes
1 answer

I had a business rules that had a PowerShell script to update User properties in a SQL table. It was working fine. I moved the PowerShell to a custom command so I could ... in the custom command does get the values for the User object. Am I missing something?

asked Jun 2, 2014 by sdavidson (730 points)
0 votes
1 answer

On Approval Requests, in the web console, Initiator shows "N/A" instead of the custom command scheduled task. The admin console shows the custom command scheduled task though. Any way to fix that?

asked Jan 21, 2021 by mark.it.admin (2.3k points)
3,569 questions
3,259 answers
8,275 comments
547,985 users