I am looking for Veeam powershell script to list jobname, server, status and last run for last 24 hours . this should include backup and copy jobs.
Kindly assist.
I am looking for Veeam powershell script to list jobname, server, status and last run for last 24 hours . this should include backup and copy jobs.
Kindly assist.
Best answer by Chris.Childerhose
Import-Module Veeam.Backup.PowerShell -WarningAction SilentlyContinue
$results = @()
# Get backup copy jobs once
$backupCopyJobs = Get-VBRBackupCopyJob
$copyJobIds = $backupCopyJobs.Id
# Backup jobs only (exclude backup copy jobs)
foreach ($job in Get-VBRJob | Where-Object { $_.Id -notin $copyJobIds }) {
$lastSess = Get-VBRSession -Job $job |
Sort-Object CreationTime -Descending |
Select-Object -First 1
if (-not $lastSess) {
$results += [PSCustomObject]@{
'Job Name' = $job.Name
'Job Type' = 'Backup Job'
'Protected server name' = 'Job has not run yet'
'Status' = 'N/A'
'Last Run' = $null
}
continue
}
$fullSess = Get-VBRBackupSession -Id $lastSess.Id
foreach ($t in Get-VBRTaskSession -Session $fullSess) {
$results += [PSCustomObject]@{
'Job Name' = $job.Name
'Job Type' = 'Backup Job'
'Protected server name' = $t.Name
'Status' = $t.Status
'Last Run' = $t.Progress.StartTimeUtc.ToString('M/d/yyyy h:mm:ss tt') + ' UTC'
}
}
}
# Backup copy jobs
$allJobs = Get-VBRJob
$allBackupSessions = Get-VBRBackupSession
foreach ($copyJob in $backupCopyJobs) {
$convJob = $allJobs | Where-Object { $_.Id -eq $copyJob.Id }
if (-not $convJob) {
$results += [PSCustomObject]@{
'Job Name' = $copyJob.Name
'Job Type' = 'Backup Copy Job'
'Protected server name' = 'Unable to map copy job'
'Status' = 'Unknown'
'Last Run' = $null
}
continue
}
$workerJobs = $convJob.GetWorkerJobs()
$copySessions = @()
foreach ($worker in $workerJobs) {
$copySessions += $allBackupSessions | Where-Object { $_.JobId -eq $worker.Id }
}
$lastSess = $copySessions |
Sort-Object CreationTime -Descending |
Select-Object -First 1
if (-not $lastSess) {
$results += [PSCustomObject]@{
'Job Name' = $copyJob.Name
'Job Type' = 'Backup Copy Job'
'Protected server name' = 'Job has not run yet'
'Status' = 'N/A'
'Last Run' = $null
}
continue
}
foreach ($t in Get-VBRTaskSession -Session $lastSess) {
$results += [PSCustomObject]@{
'Job Name' = $copyJob.Name
'Job Type' = 'Backup Copy Job'
'Protected server name' = $t.Name
'Status' = $t.Status
'Last Run' = $t.Progress.StartTimeUtc.ToString('M/d/yyyy h:mm:ss tt') + ' UTC'
}
}
}
$results = $results | Sort-Object 'Job Type', 'Job Name', 'Protected server name'
# Show on screen
$results | Format-Table 'Job Name', 'Job Type', 'Protected server name', 'Status', 'Last Run' -AutoSize
# Export CSV
$csvPath = "E:\Software\Reports\VeeamJobDetails-Servers.csv"
$results | Export-Csv -Path $csvPath -NoTypeInformation -Encoding UTF8
Write-Host "CSV exported to $csvPath"
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.