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.