PowerShell script exchange
Post Reply
pinkerton
Enthusiast
Posts: 82
Liked: 4 times
Joined: Sep 29, 2011 9:57 am
Contact:

Q: Starting Job remote via PS and check success?

Post by pinkerton »

Dear Experts,

we would like to externally schedule and start one of our Veeam Jobs using a solution called Automic Automation Engine (formerly known as UC4). In order for this to work, I guess I just need a PowerShell script for starting the job whose execution is scheduled and triggered by the remote software. However, the plan is not just to schedule and start the job but also to find out whether it was successful and if yes to execute another script which performs some additional tasks within the machine that was backed up. So basically:

1. Remote software executes script which starts the backup job
2. If job was successful, the remote software executes another script, if not it generates a warning message

I don't have much to do with scripting and I currently don't have an understanding about how the remote software can find out whether the backup job was successful or not. I understand that a script can handover an "exit code" to inform whether it ran successfully or not. In case the remote software uses that "exit code" to determine the status - will an exit code of success (i.e. 0) mean that the backup ran successfully (or at least finished, be it successful or not) or does it just mean that the script successfully completed and started the backup job? If an exit code of success means that the backup was successful (or finished) I guess the execution of the scripts lasts until the backup completes and not only for time needed to start the job?

Is the exit code always available after a PowerShell script completes? For instance, if using just a one-lined script to start the backup job like this:

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
Start-VBRJob "Test"
Is the exit code available without adding additional code to the script so it can be used by the remote software to determine whether the execution of the script (or completion of backup) was successful or not?

Sorry for asking so many questions which might seem a little dumb but as said above, usually I don't have anything to do with scripting.

Thanks,
Michael
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Q: Starting Job remote via PS and check success?

Post by veremin »

By default, lines in PS are processed one by one. Before proceeding to the next line the script will wait till the previous one is finished.

So, you can add just one line that will check whether or not the last backup session has ended successfully:

Code: Select all

$Job = Get-VBRJob -name "Name of your Job"
Start-VBRJob -Job $Job
$Job.GetLastResult() -eq "Success"
The result of this script will be either True or False.

Thanks.
pinkerton
Enthusiast
Posts: 82
Liked: 4 times
Joined: Sep 29, 2011 9:57 am
Contact:

Re: Q: Starting Job remote via PS and check success?

Post by pinkerton »

Thanks, $Job.GetLastResult() seems to return the status of the backup. Regarding the exit code - is this always returned (0 or 1) after a script has been finished? Does the Exit Code refer to the last line in the script (so it determines whether that command ran successfully or not?) or to the completion of the whole script?.
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Q: Starting Job remote via PS and check success?

Post by veremin »

Does the Exit Code refer to the last line in the script?
It depends on what particular exit code you're referring to (inside script or outside). You might want to get familiar with this article; should clarify your questions. Thanks.
pinkerton
Enthusiast
Posts: 82
Liked: 4 times
Joined: Sep 29, 2011 9:57 am
Contact:

Re: Q: Starting Job remote via PS and check success?

Post by pinkerton »

Thank you, I will give this a shot!
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests