Unsuccesful jobs

PowerShell script exchange

Unsuccesful jobs

Veeam Logoby masonit » Fri Apr 19, 2013 8:55 am

Hi!

I want to create a script that list all unsuccessful jobs the last 24 h. Only jobs that has ended as unsuccesful. Not jobs that failed but retry went fine. Also I want to see what job the failed vm is associated with and the description of that job. Some help would be very appreciated. :)

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Fri Apr 19, 2013 9:47 am

In the way I see it, the following one-liner should meet your expectations:

Code: Select all
asnp VeeamPSSnapin
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and ($_.GetLastResult() -eq "Failed")} | Select-Object -Property @{N="Name";E={$_.Name}} , @{N="Objects in Job";E={$_.GetViOijs().Name}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby kamalkant » Mon Apr 22, 2013 5:54 am

I have been looking something similar. we have enterprise manager installed, which send out daily failed jobs report. But I want unsuccessful jobs reports for 24 hours ( i don't want those failed which was succeeded in next retry) , not sure if such setting can be done in enterprise manager or a script can work.
kamalkant
Influencer
 
Posts: 24
Liked: 1 time
Joined: Mon Feb 04, 2013 10:45 am
Full Name: kamalkant singhal

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon Apr 22, 2013 6:53 am

Hi, Kamalkant.

I believe that the script provided above is exactly what you need. It lists all the jobs for 24 hours that failed during last session. Additionally, it outputs job objects (VMs), as well, as job description.

If you’re willing to see some modified version of this script, don’t hesitate to let me know.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby masonit » Mon Apr 22, 2013 7:05 am

v.Eremin wrote:In the way I see it, the following one-liner should meet your expectations:

Code: Select all
asnp VeeamPSSnapin
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and ($_.GetLastResult() -eq "Failed")} | Select-Object -Property @{N="Name";E={$_.Name}} , @{N="Objects in Job";E={$_.GetViOijs().Name}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table

Hope this helps.
Thanks.


Wow that looks really good, thanks! :)

Is it possible to also get the jobs with warnings?

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby kamalkant » Mon Apr 22, 2013 7:45 am

Thanks Eremin,

when I run it from my enterprise veeam server, it shows only the unsuccessful jobs which are on the Veeam server. we have veean installed on enterprise server also. Other than that we have many more veeam servers in different sites. I want to avoid logging to each veeam server to check these data daily. Enterprise manager send a report daily talking about all failed jobs, but not the unsuccessful ones.
kamalkant
Influencer
 
Posts: 24
Liked: 1 time
Joined: Mon Feb 04, 2013 10:45 am
Full Name: kamalkant singhal

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon Apr 22, 2013 8:19 am

Other than that we have many more veeam servers in different sites.

In this case you can utilize remote PS execution, so that, script executed on your central server will establish connection with other machines, collect from them information regarding backup jobs, and finally output it in one console.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon Apr 22, 2013 8:35 am

Is it possible to also get the jobs with warnings?

Yep, the only thing you need to do is to replace “Failed” with “Warning”:

Code: Select all
asnp VeeamPSSnapin
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and ($_.GetLastResult() -eq "Warning")} | Select-Object -Property @{N="Name";E={$_.Name}} , @{N="Objects in Job";E={$_.GetViOijs().Name}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby masonit » Mon Apr 22, 2013 8:58 am

Yes that I understand... :)

But is it possible to specify them both in the same line?

I also saw now that it specify all the vms in the job. I would like to only see the vms that has a warning/failed in the job.

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon Apr 22, 2013 9:08 am

But is it possible to specify them both in the same line?

Ok, I’ve got your point. Then, you need to add “–and” parameter in order to combine both statuses within one script:

Code: Select all
asnp VeeamPSSnapin
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and (($_.GetLastResult() -eq "Warning") -or ($_.GetLastResult() -eq "Failed"))} | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Objects in Job";E={$_.GetViOijs().Name}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table


Moreover, for the purpose of convenience I’ve added “Last status” column to the output table.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon Apr 22, 2013 12:59 pm

I also saw now that it specify all the vms in the job. I would like to only see the vms that has a warning/failed in the job.

In this case you need to create a function responsible for tracking the given job objects that failed during last 24 hours and then output them among other parameters:

Code: Select all
asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-24)}
  foreach ($session in $Sessions)
  {
     ($session.Gettasksessions() | ? {$_.Status -eq "Failed"}).name
  }
}
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and (($_.GetLastResult() -eq "Warning") -or ($_.GetLastResult() -eq "Failed"))} | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Failed VM";E={Failed $_}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby masonit » Mon May 13, 2013 9:23 am

v.Eremin wrote:
I also saw now that it specify all the vms in the job. I would like to only see the vms that has a warning/failed in the job.

In this case you need to create a function responsible for tracking the given job objects that failed during last 24 hours and then output them among other parameters:

Hope this helps.
Thanks.


Thank you v.Eremin! Almost works. It doesn't show the name of the failed vm. It only shows warning:

Last result Failed VM
Warning

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon May 13, 2013 10:50 am

Oh, shame on me but the custom “Failed” function didn’t take into account warning session, therefore, you didn’t see the name of the corresponding “Warning” VMs.

So, the code provided above should be modified a little bit:

Code: Select all
asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-24)}
  foreach ($session in $Sessions)
  {
     ($session.Gettasksessions() | ? {$_.Status -eq "Failed" -or $_.Status -eq "Warning"}).name
  }
}
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and (($_.GetLastResult() -eq "Warning") -or ($_.GetLastResult() -eq "Failed"))} | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Failed VM\VM with warnings";E={Failed $_}} , @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby Andreas Neufert » Mon May 13, 2013 7:58 pm

Hi Vladimir,
great work... I added a link to the "Getting Started and Code Examples " section.
Thank you ... Andy
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Unsuccesful jobs

Veeam Logoby masonit » Tue May 14, 2013 6:59 am

v.Eremin wrote:Oh, shame on me but the custom “Failed” function didn’t take into account warning session, therefore, you didn’t see the name of the corresponding “Warning” VMs.

So, the code provided above should be modified a little bit:

Hope this helps.
Thanks.


Hi again. :)

Warning works fine now but when I get at failed error the the vm name doesn't show. Tried to solve it myself but no luck. :(

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests