Automate Veeam Agent Upgrades via VSPC

  • 18 December 2023

Userlevel 2

One of the things I have been looking at recently is automating the process of upgrading Veeam Agents. The great thing with Veeam Service Provider Console is how easy we can bulk update agents from one place. However, I wanted to take it a step further and have this totally automated - mainly because I am lazy. To do so, I have used the VSPC API to do this for me. I am not the most proficient with PowerShell, someone can probably make this run more efficiently. However the below script works just fine for me, so thought I would share it with the community. I use this via an Azure Function that runs every morning and kicks off an upgrade of any agents that require it, however you could schedule this from a RMM product etc, whatever works best for yourself. At the moment there is no property in the VSPC API to show if an agent requires an upgrade, so it starts by adding this property by comparing the installed version to the current released version (this part you manually have to update). It also filters out any agents that have tasks running, as I don’t want to start upgrading an agent if a backup is in progress. 


Add-Type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer AddTokenHere")

## Connect to VSPC API and collect info on Veeam Agent Details ##

$Report = Invoke-RestMethod 'https://VSPC-URL/api/v3/infrastructure/backupAgents' -Method 'GET' -Headers $headers

## Get all Veeam Agents that are Managed by Console that have no running backups ## 

$Agents = $ | Where-Object {$_.managementMode -eq "ManagedByConsole" -and $_.runningJobsCount -eq "0"}

## Manually update the current Veeam for Agent Version, nothing in API to show if an upgrade is required, so manual until this is available ##

$CurrentVersion = [Version]""

## Create an array and add in if the agent requires an upgrade or not ##

$Table = @()
Foreach($Agent in $Agents)

$Name = $
$Version = [version]$agent.version
$AgentUID = $agent.instanceUid

If($Version -lt $CurrentVersion)

    $upgrade = "UpdateRequired"

ELSEIF($Version -eq $CurrentVersion)
    $upgrade = "UpToDate"

$TA = New-Object System.Object

$TA | Add-Member -MemberType NoteProperty -Name Name -Value $Name
$TA | Add-Member -MemberType NoteProperty -Name InstanceUID -Value $AgentUID
$TA | Add-Member -MemberType NoteProperty -Name Version -Value $Version
$Ta | Add-Member -MemberType NoteProperty -Name Update -Value $upgrade

$Table += $TA


## Filter out the up to date agents and list only the agents that require an upgade ##

$UpgradeNeeded = $Table | Where-Object {$_.Update -eq "UpdateRequired"}

## For each agent that requires an upgrade, kick the upgrade off ## 

Foreach($Up in $UpgradeNeeded)
$upgradeInstanceUID = $up.InstanceUID

$UpgradeAgent = Invoke-RestMethod "https://VSPC-URL/api/v3/infrastructure/backupAgents/windows/$UpgradeInstanceUID/update" -Method 'POST' -Headers $headers



Userlevel 7
Badge +17

Fine solution @keironbell  👍🏼

This should work in a similar way with server managed agents via the VBR Rest API, too.
I haven’t scripted it myself up to now, but the functionality should be there….

Userlevel 2

Yeah, we can just remove the filter for “ManagedByConsole”, I just wanted to keep them separate for now, whilst we still need to upgrade those VBR’s to 12.1 :) 

Userlevel 7
Badge +17

I meant that it should work in a similar way via the Veeam Backup & Replication REST API, too - instead of the Veeam Service Provider Console REST API.

Userlevel 7
Badge +19

Nice script @keironbell . Appreciate the share!

Userlevel 7
Badge +21

Never really looked at the APIs personally but this is very interesting to be able to upgrade agents.  Not sure we could do this with our clients but something to test for sure.  Thanks for sharing the script.

Userlevel 7
Badge +10

Thank you for sharing @keironbell 👍