PowerShell script exchange
Post Reply
skaanbarry
Influencer
Posts: 10
Liked: never
Joined: Mar 22, 2022 8:07 am
Contact:

Powershell - get latest result from Backup & Copy jobs

Post by skaanbarry »

Hi guys,

I'm somewhat of a PS noob and looking for a way to run a miniscript daily that gives the latest run result of my backup & copy jobs. I also need to export that in .csv for data for our monitioring dashboard.

With the "Get-VBRJob" I get the correct output , however when I try to export it to Csv the "Last Result" output is nowhere to be found..

Does anyone know why or can help me create my script?
skaanbarry
Influencer
Posts: 10
Liked: never
Joined: Mar 22, 2022 8:07 am
Contact:

Re: Powershell - get latest result from Backup & Copy jobs

Post by skaanbarry »

My colleague helped me out and we got this script working for the Backup Jobs but NOT for Copy jobs.

"
Connect-VBRServer -Server 10.101.15.63

$ListJobs = Get-VBRJob -Name *Copy*
$ListSession = Get-VBRBackupSession
$summary = @()
foreach ($job in $ListJobs) {
$lastSession = $ListSession | where {$_.JobId -eq $job.Id} | sort -Property EndTime | select -Last 1
$summary += $job | select Name, @{n='LastResult';e={$lastSession.Result}}
}
$summary | export-csv C:\BackupReports\BackupCopy.csv
"

However when I run this for my Copy Jobs, the Last Result output is empty. Any ideas?
DanielJ
Service Provider
Posts: 200
Liked: 32 times
Joined: Jun 10, 2019 12:19 pm
Full Name: Daniel Johansson
Contact:

Re: Powershell - get latest result from Backup & Copy jobs

Post by DanielJ »

I think you will have to get all sessions like this instead, or you will only get ordinary backup jobs:

$ListSession = [Veeam.Backup.Core.CBackupSession]::GetAll()
skaanbarry
Influencer
Posts: 10
Liked: never
Joined: Mar 22, 2022 8:07 am
Contact:

Re: Powershell - get latest result from Backup & Copy jobs

Post by skaanbarry »

Like this? It did not do the trick. It finds the copy jobs though, because they show in the first column.

However the second column "LastResult" is empty.

Connect-VBRServer -Server 10.101.15.63

$ListJobs = Get-VBRJob -Name *Copy*
$ListSession = [Veeam.Backup.Core.CBackupSession]::GetAll()
$summary = @()
foreach ($job in $ListJobs) {
$lastSession = $ListSession | where {$_.JobId -eq $job.Id} | sort -Property EndTime | select -Last 1
$summary += $job | select Name, @{n='LastResult';e={$lastSession.Result}}
}
$summary | export-csv C:\BackupReports\CopyReport_-$((Get-Date).ToString('dd-MM-yyyy')).csv
DanielJ
Service Provider
Posts: 200
Liked: 32 times
Joined: Jun 10, 2019 12:19 pm
Full Name: Daniel Johansson
Contact:

Re: Powershell - get latest result from Backup & Copy jobs

Post by DanielJ »

Try changing the second line in the foreach loop to this:

$summary += $lastsession|select JobName, Result

The jobname is there in the session, so no need to get it from the job. With this change I get the correct value in the LastResult column - the problem is that the value is "None" since the sessions only get a result when they are finished, and the last session of a copy job will still be running (unless the job was disabled). So you would need to look at the next to last session, for example by removing the "select -Last 1" part and then look at $lastSession[-2], after checking that the array has at least 2 objects in it.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests