GetLastResult() returns NONE

PowerShell script exchange

GetLastResult() returns NONE

Veeam Logoby bttw » Fri 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?
bttw
Novice
 
Posts: 4
Liked: 3 times
Joined: Thu Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell

Re: GetLastResult() returns NONE

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

Re: GetLastResult() returns NONE

Veeam Logoby bttw » Fri 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: Thu Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell

Re: GetLastResult() returns NONE

Veeam Logoby bttw » Mon 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: Thu Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell

Re: GetLastResult() returns NONE

Veeam Logoby bttw » Mon 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.
bttw
Novice
 
Posts: 4
Liked: 3 times
Joined: Thu Dec 06, 2012 4:59 pm
Full Name: Wes Jerrell

Re: GetLastResult() returns NONE

Veeam Logoby v.Eremin » Mon 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!
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: GetLastResult() returns NONE

Veeam Logoby tsightler » Tue 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.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: GetLastResult() returns NONE

Veeam Logoby Oka Soh » Tue 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?
Oka Soh
Influencer
 
Posts: 11
Liked: never
Joined: Fri Jul 05, 2013 1:50 am
Full Name: Sohei Okamoto

Re: GetLastResult() returns NONE

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


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests