PowerShell script exchange
Post Reply
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Unsuccesful jobs

Post by masonit »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
kamalkant
Influencer
Posts: 24
Liked: 1 time
Joined: Feb 04, 2013 10:45 am
Full Name: kamalkant singhal
Contact:

Re: Unsuccesful jobs

Post by kamalkant »

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.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

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
kamalkant
Influencer
Posts: 24
Liked: 1 time
Joined: Feb 04, 2013 10:45 am
Full Name: kamalkant singhal
Contact:

Re: Unsuccesful jobs

Post by kamalkant »

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.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

v.Eremin wrote: 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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

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.
Andreas Neufert
VP, Product Management
Posts: 7076
Liked: 1510 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Unsuccesful jobs

Post by Andreas Neufert »

Hi Vladimir,
great work... I added a link to the "Getting Started and Code Examples " section.
Thank you ... Andy
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

So, are you saying that the names of corresponding VM (“Failed VM/VM with warnings”) in case of “Warning” session are shown correctly, but in case of “Failed” session you get a blank field, instead?

Honestly, I just checked it and everything seemed to work properly. Below you can find the result I got:

Code: Select all

Name                                        Last result Failed VM\VM with warnings Description               
----                                        ----------- -------------------------- -----------               
Replication Job 4                                Failed {Win7_migrated, Win7_mi... Created by V65\Administ...
Backup Job 3                                     Failed {Win8n3, Win8n2, Win8n4}   Custom description    
Anyway, what if you modify the aforesaid code a little bit, creating different “Warning” function responsible for listing only “Warning” sessions, separating it from "Failed" function, and changing slightly body of the script?

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"}
  }
}
Function Warning([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 "Warning"}
  }
}
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 $_).name}} ,@{N="VM with warning";E={(Warning $_).name}}, @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table


Hope this helps.
Thanks.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

Hi Vladimir,
great work... I added a link to the "Getting Started and Code Examples " section.
Thank you ... Andy
I’m wondering whether everything works as expected in your environment, or you’re facing the similar issue as Magnus with the VM names not being shown correctly.

Thanks.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

v.Eremin wrote:So, are you saying that the names of corresponding VM (“Failed VM/VM with warnings”) in case of “Warning” session are shown correctly, but in case of “Failed” session you get a blank field, instead?
Exact!

I tried the the other script but I got the same problem with that:

Last result Failed VM VM with warning
Warning prodapptok01
Warning DRSTEAP07
Failed

I am using VBR 6.5.0.128 with powershell 3.0.

\Masonit
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

Can you confirm that, at least, one VM has failed during last session?

It can be the means of the following script:

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"}
  }
} 
$Job = Get-VbrJob -name "Name of your job"
Failed $Job | Select name 
If as the result of this script execution you get blank list, it means that no VM has failed during last backup session.

Thanks.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

v.Eremin wrote:Can you confirm that, at least, one VM has failed during last session?
I can not run that script. I get "VeeamPSS is not installed on this computer".

I have just created two test jobs that has failed. I see them both but not the VMs:

Code: Select all

Name                                                                   Last result Failed VM\VM with warnings               Description
Backup Job 104                                                              Failed                                          Created by * at 2013-05-14 13...
Backup Job 103                                                              Failed                                          Created by * at 2013-05-14 13...
\Masonit
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

I can not run that script. I get "VeeamPSS is not installed on this computer".
I’ve corrected the typo already, so, please, try again.

As to the sessions, please be aware that if the job has finished with “Failed” status, it doesn’t necessarily mean that some VM has failed during last session. For instance, if the job was manually stopped at the very begging (even before it managed to process any Virtual Machine), it'd result in "Failed" job status, meanwhile, none of the VM literally failed, etc.

Thanks.
EPSMAL
Lurker
Posts: 0
Liked: never
Joined: Aug 07, 2012 6:37 am
Full Name: EPSMAL
Contact:

[MERGED] : list all VM for each job

Post by EPSMAL »

Hello everybody,

i have a problem with a script.
i would like to list for each job, the backup result for each VM.

Code: Select all

foreach($Job in (Get-VBRJob )) {
	$Session = $Job.FindLastSession()
	$Info = $Session.GetTaskSessions()
foreach ($VM in $info) {
echo $job.Name
echo $VM.Name
echo $VM.status
}
}
i have 2 jobs : LINUX and WINDOWS
when the status job is sucess : there are no problem, all VMs are listed
but for exemple, when a job has failed and when the job has retried , i have a few VMs because de lastjob is the job who has been retried

How can i list all vms ?
thanks for your help
best regards
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

You’ve been merged to the existing discussion which is concerned with similar issue.

From my perspective, if you modify code provided above, you'll be able to meet your expectations:

Code: Select all

asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
     $Job.FindLastSession().Gettasksessions() | ? {$_.Status -eq "Failed"}
}
Function Warning([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-$Interval)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Warning"}
  }
}
Function Successful([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-$Interval)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Success"}
  }
}
$Job = Get-VBRJob -name (read-host "Name of your Job")
$Interval = ([datetime]$Job.ScheduleOptions.NextRun).Subtract([datetime]$Job.ScheduleOptions.LatestRun).TotalHours 
Get-VBRJob -name $Job.name | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Failed VM";E={(Failed $_).name}} ,@{N="VM with warning";E={(Warning $_).name}},@{N="Successful";E={(Successful $_).name}}| Sort Name -Descending | Format-Table
Firstly, you’ll be asked to input name of the corresponding job.

Secondly, the script will determine the interval throughout which it will try to find job sessions. The interval is defined as a time period between latest job run and the next one. In general, the interval is required in order to catch only those task sessions that are related to the latest job run.

Thirdly, the determined interval, as well as, the job name will be passed to custom functions (Failed, VM with warnings, Successful).

Fourthly, custom functions, using the passed interval, will find VM with corresponding status.

Fifthly, the script will create a table using the data provided by custom functions. As the result you will get something like this:

Code: Select all

Name of your Job: Vi-Test#50

Name                                           Last result Failed VM                    VM with warning              Successful                  
----                                           ----------- ---------                    ---------------              ----------                  
VI-Test#50                                          Failed VM#3                                                                          


To be honest, I haven’t had enough time/resources to test this script thoughtfully, thus, all comments/feedback are highly-appreciated.

Hope this helps.
Thanks.
EPSMAL
Lurker
Posts: 0
Liked: never
Joined: Aug 07, 2012 6:37 am
Full Name: EPSMAL
Contact:

Unsuccesful jobs

Post by EPSMAL »

Hello, thanks for your answers.

I am going to test it.

Thanks

best regards
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

I’ve split your answer in order not to overfill the existing topic with irrelevant discussion.

Thanks.
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Unsuccesful jobs

Post by masonit »

v.Eremin wrote: I’ve corrected the typo already, so, please, try again.

As to the sessions, please be aware that if the job has finished with “Failed” status, it doesn’t necessarily mean that some VM has failed during last session. For instance, if the job was manually stopped at the very begging (even before it managed to process any Virtual Machine), it'd result in "Failed" job status, meanwhile, none of the VM literally failed, etc.

Thanks.
Hi v.Eremin, still can't run the script: Object reference not set to an instance of an object

But never mind. Today the script runs fine. I get VM name on all failed jobs! :)
I saw now that the failed job with the vm name that didn't show. That job was started manually and not as a scheduled job. Could that explain the issue?

\Masonit
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Unsuccesful jobs

Post by veremin »

Could that explain the issue?
No, I believe, it can’t be the issue, since all task sessions (be it manual job execution or automatic one) are tracked in the same manner.

Anyway, glad to hear that nowadays everything works as expected.

Should any other questions arise, don’t hesitate to contact me. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests