PowerShell script exchange
Post Reply
bttw
Novice
Posts: 4
Liked: 3 times
Joined: Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell
Contact:

GetLastResult() returns NONE

Post by bttw » Jun 05, 2015 12:57 pm

I recently upgraded to Version 8 from Version 7 of Backup & Replication. My scripts have worked fine for several years. Since the upgrade, my post-job scripts are failing. I added some logging and figured out that the Veeam was returning an incorrect value during the GetLastResult() portion of the script below. If I execute the script manually (as the same user that runs the Veeam Backup Service), I get the proper result of either, "Success," "Warning" or "Failed." When Veeam calls the script, it returns "None"

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRJob -name "vCenter"
$lastresult = $job.GetLastresult()
Write-EventLog -LogName "Veeam Backup" -Source "Veeam Scripting" -EntryType Information -EventID 300 -Message "Post-Job Script Reports Veeam job as $lastresult"
Any ideas on what would be the cause?

v.eremin
Product Manager
Posts: 16232
Liked: 1325 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: GetLastResult() returns NONE

Post by v.eremin » Jun 05, 2015 5:52 pm

What happens if you rewrite the script slightly:

Code: Select all

    asnp VeeamPSSnapin
    $Job = Get-VBRJob -name "vCenter"
    $lastresult = $job.FindLastSession().Result
Thanks.

bttw
Novice
Posts: 4
Liked: 3 times
Joined: Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell
Contact:

Re: GetLastResult() returns NONE

Post by bttw » Jun 05, 2015 6:11 pm

v.Eremin wrote:What happens if you rewrite the script slightly:

Code: Select all

    asnp VeeamPSSnapin
    $Job = Get-VBRJob -name "vCenter"
    $lastresult = $job.FindLastSession().Result
Thanks.
Same result. Veeam is returning a value of "None." Thanks for taking a stab at it!

bttw
Novice
Posts: 4
Liked: 3 times
Joined: Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell
Contact:

Re: GetLastResult() returns NONE

Post by bttw » Jun 08, 2015 3:35 pm

Veeam support was able to reproduce the problem in their test lab. They have escalated the case. I'll update the thread with any findings.

bttw
Novice
Posts: 4
Liked: 3 times
Joined: Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell
Contact:

Re: GetLastResult() returns NONE

Post by bttw » Jun 08, 2015 9:09 pm 3 people like this post

The solution was two parts. Part 1 is to have Veeam call a batch file that calls the Powershell script with the "start" command so the batch file can finish executing and close.

Batch File:

Code: Select all

start C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Tools\DumpvCenter.ps1"
Then, in the Powershell script, I needed to add a while loop to check for the "IsRunning" property. This should allow the job to finish up, get a correct Success/Failed value and allow the rest of my script to execute.

Powershell:

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRJob -name "vCenter"
while ($Job.IsRunning -eq "True")
{
    Start-Sleep -s 10
}
$lastresult = $Job.FindLastSession().Result
I hope this helps someone in the future.

v.eremin
Product Manager
Posts: 16232
Liked: 1325 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: GetLastResult() returns NONE

Post by v.eremin » Jun 08, 2015 10:11 pm

Ok, I must have forgotten that now scripts are considered to be a part of job session, so, the result of it is not updated, till post-job activity script finishes. The batch file with start command executing PS script that makes use of IsRunning property is indeed a nice workaround. Thanks for posting!

tsightler
VP, Product Management
Posts: 5310
Liked: 2162 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: GetLastResult() returns NONE

Post by tsightler » Jun 09, 2015 1:59 am

Indeed, this basically is the same workaround I used when I discovered this change in v8 behavior back of few months ago. Sorry I didn't see this thread sooner, could have perhaps saved you some time, but thanks very much for sharing with the community.

Oka Soh
Influencer
Posts: 11
Liked: never
Joined: Jul 05, 2013 1:50 am
Full Name: Sohei Okamoto
Contact:

Re: GetLastResult() returns NONE

Post by Oka Soh » Jul 07, 2015 9:42 am

v.Eremin wrote: now scripts are considered to be a part of job session,
Sorry for using old thread.
Were there any critical issue which led to such a change?

v.eremin
Product Manager
Posts: 16232
Liked: 1325 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: GetLastResult() returns NONE

Post by v.eremin » Jul 07, 2015 10:15 am

Just a common sense, scripts are considered to be a part of job cycle. So, not until scripts are passed, the job result be updated. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests