Q: Starting Job remote via PS and check success?

PowerShell script exchange

Q: Starting Job remote via PS and check success?

Veeam Logoby pinkerton » Wed Feb 18, 2015 3:36 pm

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
pinkerton
Enthusiast
 
Posts: 62
Liked: 4 times
Joined: Thu Sep 29, 2011 9:57 am

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

Veeam Logoby v.Eremin » Wed Feb 18, 2015 3:50 pm

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.
v.Eremin
Veeam Software
 
Posts: 13291
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

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

Veeam Logoby pinkerton » Thu Feb 19, 2015 7:33 am

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?.
pinkerton
Enthusiast
 
Posts: 62
Liked: 4 times
Joined: Thu Sep 29, 2011 9:57 am

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

Veeam Logoby v.Eremin » Thu Feb 19, 2015 12:26 pm

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.
v.Eremin
Veeam Software
 
Posts: 13291
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

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

Veeam Logoby pinkerton » Mon Feb 23, 2015 3:46 pm

Thank you, I will give this a shot!
pinkerton
Enthusiast
 
Posts: 62
Liked: 4 times
Joined: Thu Sep 29, 2011 9:57 am


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 7 guests