Skip to main content

I have single veeam backup policy with contains of 10 VMs.

How we can get backup status for each VM to knowing the VM is backup is successful or not using powershell?

 

Hi ​@hs08, don’t know if i get you correct (if you want to use/or not to use PowerShell), but:

  • you can see the state within the job result itself
  • you can check within the History section
  • you can receive a report by mail - this will list all protected workloads (so in your case 10 VMs)
  • you can use Veeam ONE and/or Enterprise Manager to track state of your jobs.
  • you can track the details within vSphere of the VMs (as an attribute)
  • depend on your Monitoring solution, this solution could track this maybe as well.

 

If it’s related to PowerShell:

  • besides that, here is the PowerShell Reference Managing Backups - Veeam Backup PowerShell Reference
    • example to get your jobs: 
      • Get-VBRJob
    • for getting the selection within your jobs: 
      • foreach($job in Get-VBRJob) { Write-Host "Job:", $job.Name; $job.GetObjectsInJob() | foreach { $_.Location } }

 

  • if you want only the selected ressources within a specific job, try this:
    • # Load Veeam PowerShell Snap-In (if not already loaded)
      Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue

      # Name of the backup job
      $jobName = "NAMEOFYOURJOB"

      # Get the backup job
      $job = Get-VBRJob -Name $jobName

      if ($job -eq $null) {
          Write-Host "Backup job '$jobName' was not found."
          return
      }

      # List all objects (VMs) in the job
      $jobObjects = Get-VBRJobObject -Job $job

      # Format and display the output
      $jobObjects | Select-Object Name, Type | Format-Table -AutoSize
       

 

 

EDIT:

the command above would list the selection within the Job, if these are VMs, you would be good to go. In my case, i work with Tags or Folders as a selection, then you could go with this:

 

# Load Veeam PowerShell Snap-In
Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue

# Job name
$jobName = "NAMEOFYOURJOB"

# Get the job
$job = Get-VBRJob -Name $jobName

if ($job -eq $null) {
    Write-Host "Backup job '$jobName' not found."
    return
}

# Get the latest session of the job
$lastSession = $job.FindLastSession()

if ($lastSession -eq $null) {
    Write-Host "No sessions found for job '$jobName'."
    return
}

# Get all processed VMs in the last session
$sessionObjects = Get-VBRBackupSession -Id $lastSession.Id |
    Get-VBRTaskSession |
    Where-Object {$_.Info.Progress -ne $null} |
    Select-Object @{Name="VMName";Expression={$_.Name}}, 
                  @{Name="Status";Expression={$_.Status}}, 
                  @{Name="LastResult";Expression={$_.Info.Result}}, 
                  @{Name="BackupSize(GB)";Expression={ math]::Round($_.Info.BackupSize/1GB, 2)}}

# Output
$sessionObjects | Format-Table -AutoSize
 

 
 

 

 

Below some examples (within VBR)…

 

 

Hope this helps

 

 

 


After asking ChatGPT again and tweaking the output to this….

 

# Load Veeam PowerShell Snap-In
Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue

# Job name
$jobName = "NAMEOFYOURJOB"

# Get the job
$job = Get-VBRJob -Name $jobName

if ($job -eq $null) {
Write-Host "Backup job '$jobName' not found."
return
}

# Get the latest session of the job
$lastSession = $job.FindLastSession()

if ($lastSession -eq $null) {
Write-Host "No sessions found for job '$jobName'."
return
}

# Get all processed VMs in the last session
$sessionObjects = Get-VBRBackupSession -Id $lastSession.Id |
Get-VBRTaskSession |
Where-Object {$_.Info.Progress -ne $null} |
Select-Object @{Name="VMName";Expression={$_.Name}},
@{Name="Status";Expression={$_.Status}},
@{Name="Result";Expression={$_.Info.Result}},
@{Name="ProcessedSize(GB)";Expression={nmath]::Round($_.Info.Progress.ProcessedSize/1GB, 2)}},
@{Name="TransferredSize(GB)";Expression={nmath]::Round($_.Info.Progress.TransferedSize/1GB, 2)}}

# Output
$sessionObjects | Format-Table -AutoSize

 

you will get this:

 

 


Hi ​@hs08 ,

there is also a finished reporting script available on Github called “MyVeeamReport” maybe this could help.

https://github.com/marcohorstmann/MyVeeamReport


Further to what everyone here has said if you want a very quick way to check then you can install the vSphere plugin from Enterprise Manager and it will show you at a glance if your VM is backed up.

 


After asking ChatGPT again and tweaking the output to this….

 

# Load Veeam PowerShell Snap-In
Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue

# Job name
$jobName = "NAMEOFYOURJOB"

# Get the job
$job = Get-VBRJob -Name $jobName

if ($job -eq $null) {
Write-Host "Backup job '$jobName' not found."
return
}

# Get the latest session of the job
$lastSession = $job.FindLastSession()

if ($lastSession -eq $null) {
Write-Host "No sessions found for job '$jobName'."
return
}

# Get all processed VMs in the last session
$sessionObjects = Get-VBRBackupSession -Id $lastSession.Id |
Get-VBRTaskSession |
Where-Object {$_.Info.Progress -ne $null} |
Select-Object @{Name="VMName";Expression={$_.Name}},
@{Name="Status";Expression={$_.Status}},
@{Name="Result";Expression={$_.Info.Result}},
@{Name="ProcessedSize(GB)";Expression={nmath]::Round($_.Info.Progress.ProcessedSize/1GB, 2)}},
@{Name="TransferredSize(GB)";Expression={nmath]::Round($_.Info.Progress.TransferedSize/1GB, 2)}}

# Output
$sessionObjects | Format-Table -AutoSize

 

 

Very sorry to do this, but looks like ChatGPT introduced a few problems here (bad practices, invalid properties, etc), and wanted to correct it with some commentary, as the script would likely break on a moderately busy VBR server in production. I added notes on the bottom, and again sorry I know posts like these are annoying, but ChatGPT really cannot be trusted, it’s filled with too many awful practices and incorrect scripts so much that you pretty much need to already know how to write a good script to avoid getting bad (and potentially dangerous ) code from the LLMs.

# Job name
$jobName = "db-test"

# Get the job
$job = Get-VBRJob -Name $jobName

if ($null -eq $job) {
Write-Host "Backup job '$jobName' not found."
return
}

# Get the latest session of the job
$sessions = Get-VBRSession -Job $job | Sort-Object -Property CreationTime -Descending | Select -First 1
$lastSess = Get-VBRBackupsession -Id $sessions.id -ErrorAction SilentlyContinue

if (-not($lastSess)) {
Write-Host "No sessions found for job '$jobName'."
return
}

# Get all processed VMs in the last session

$tSess = Get-VBRTaskSession -Session $lastSess
$vmSessResults = @()
Foreach($t in $tSess){
$data = dPSCustomObject]@{
JobName = $job.Name
VMName = $t.name
TaskResult = $t.Status
ProcessedSizeGB = zmath]::Round($t.Info.Progress.ProcessSize/1GB, 2)
TransferredSizeGB = zmath]::Round($t.Info.Progress.TransferedSize/1GB, 2)
}
$vmSessResults += $data
Remove-Variable data #Powershell may not update the variable properly if there are processing issues elsewhere, safest to clear the variable once written to the array
}
# Output
$vmSessResults | Format-Table -AutoSize



<# Removed content #>

### Not needed since v11, should not be in scripts anymore (v11 and later scripts almost certainly won't work with v10 and earlier too much changed)
# Load Veeam PowerShell Snap-In
#Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue
#
### Re-wrote this to remove some bad practices and difficult to update/read stuff and incorrect items.
#$sessionObjects = Get-VBRBackupSession -Id $lastSession.Id |
# Get-VBRTaskSession |
# Where-Object {$_.Info.Progress -ne $null} |
# Select-Object @{Name="VMName";Expression={$_.Name}},
# @{Name="Status";Expression={$_.Status}},
# @{Name="Result";Expression={$_.Info.Result}}, ## No Result property under $_.Info for Task Session Objects, it's Status property
# @{Name="ProcessedSize(GB)";Expression={smath]::Round($_.Info.Progress.ProcessedSize/1GB, 2)}},
# @{Name="TransferredSize(GB)";Expression={smath]::Round($_.Info.Progress.TransferedSize/1GB, 2)}}
#
#
### Don't use internal methods like FindLastSession(). Always do it a supported way, these internal methods can do strange things sometimes and it makes debugging very hard

#$lastSession = $job.FindLastSession()

 


Comment