I would like to get why a job is failing.
I make something working if the reason is because of VM with this code :
Code: Select all
$Jobs = Get-VBRJob
$ResultVeeamBRJob += Foreach ($job in $jobs)
{
Write-Log -Type Information -Message "Processing job $($Job.Name) from $VBRServer"
Try {
$LastRun = $Job.FindLastCompletedSession().Endtime.toshortdatestring()
}
Catch
{
$LastRun = "Never"
}
[PSCustomObject]@{
VBRServer = $VBRServer
Name = $Job.Name
Type = $Job.JobType
LastResult = $Job.GetLastResult()
LastRun = $LastRun
}
}
#Job with failed or error on last result
$JobToProcess= $Jobs | where {$_.GetLastResult() -ne "Success" -and $_.GetLastResult() -ne "None"}
if ($JobToProcess) {
foreach ($Job in $JobToProcess)
{
#If the issue is because of one VM and not the job itself (like no VM to backup on the job because it has been removed)
if ($Job.FindLastSession().gettasksessions())
{
foreach ($VM in $Job.FindLastSession().gettasksessions() | Where {$_.Status -ne "Success"})
{
[PSCustomObject]@{
Job = $Job.Name
VM = $VM.Name
Reason = $VM.info.reason
}
}
}
}
}
Thanks for your help