PowerShell script exchange
Post Reply
matteu
Veeam Legend
Posts: 860
Liked: 136 times
Joined: May 11, 2018 8:42 am
Contact:

Get job failed or warning reason

Post by matteu »

Hello,

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
                }
            }
        }
    }
}
However, I don't find how to do if the job is in warning state because it can't sent an email at the end or if you create a job, add manually a VM, remove the VM from the hypervisor but not in the job. The jobs will say I don't find the VM but I don't know where to find it with powershell...

Thanks for your help
david.domask
Veeam Software
Posts: 2838
Liked: 650 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get job failed or warning reason

Post by david.domask »

Hi matteu,

Unfortunately those elements from the Job Statistics Windows are not retrievable by supported methods.

You can use the unsupported workaround here to retrieve such information from the Logger class.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 1 guest