Update Veeam Global Settings with PowerShell

In this post, I’ll show you how you can update global settings in Veeam with PowerShell. This is a precursor to a follow-up article I’m going to be writing about moving your Veeam notifications to Microsoft Teams.

The reason for this post is pretty simple. Veeam makes a number of modules available via PowerShell, but none of them can change global settings. So, if you find yourself needing to change the subject of your emails, or the address they get sent to, you might find yourself logging into each of your Veeam servers to changes those settings one-by-one. But we like to automate things, so I have a solution for you!

Guide

Our first example will be updating the subject and recipient address of email notifications. I’ll then show you how to edit other settings with a similar script. Start with the following:

$Subject = "%clientname%;%computername%;%JobName%;%JobResult%"
$ToAddress = "[email protected]"

try {
    $VeeamConfiguration = Get-ItemProperty "HKLM:\Software\Veeam\Veeam Backup and Replication"

    if ($VeeamConfiguration.SqlDatabaseName -and $VeeamConfiguration.SqlInstanceName) {
        $SQL = @"
SET QUOTED_IDENTIFIER ON

USE $($VeeamConfiguration.SqlDatabaseName);

UPDATE 
    dbo.Options
SET 
    value.modify('replace value of (/CMailOptions/Subject/text())[1] with "$Subject"')
WHERE
    name = 'email_notification';

UPDATE 
    dbo.Options
SET 
    value.modify('replace value of (/CMailOptions/To/text())[1] with "$ToAddress"')
WHERE
    name = 'email_notification';
"@

        New-Item -Path "C:\Windows\LTSvc\Packages\SQLQueries" -ItemType Directory -Force | Out-Null

        $SQL | Out-File -FilePath "C:\Windows\LTSvc\Packages\SQLQueries\update-veeam-notification-subject.sql"

        $Output = (sqlcmd -S ".\$($VeeamConfiguration.SqlInstanceName)" -i "C:\Windows\LTSvc\Packages\SQLQueries\update-veeam-notification-subject.sql")
    
        if ($Output -notcontains "(1 rows affected)") {
            throw "Unable to update database."
        }
    }
}
catch {
    throw $_.Exception.Message
}

At the top, you’ll want to change the $ToAddress to whatever email address you’re going to be sending notifications to. Likewise, you may want to change the $Subject if you don’t like the formatting. We chose this so we could do some fun subject parsing with Power Automate and create a solution for monitoring our backups outside of email.

Here’s a breakdown of how this will work in ConnectWise Automate if you’re unfamiliar with PowerShell:

  • %clientname% will be replaced by the client’s name in Automate.
  • %computername% will be replaced by the name of the computer you’re running the script against.
  • %JobName% is is a variable that will be replaced by Veeam.
  • %JobResult% is also a variable that will be replaced by Veeam.

If you read through the script, you’ll see that it’s basically just:

  1. Generating a SQL query with your new email address and subject.
  2. Discovering the SQL server instance and database for Veeam from the registry.
  3. Running the SQL query via the built-in sqlcmd utility.

Now, you’ll want to run this in Automate. Create a script in Automate. I named my “*JM – Update Veeam Email Notifications“. It should look like the following:

The first line should execute the script from above. Lines 2-4 are optional, but will give you better logging if something fails.

In our setup, I have this running on-demand. Later, I may automate this, but it will require more work with creating and updating SMTP credentials, more options in the database, etc. To capture all of your Veeam servers, I would suggest creating a search and tie it to a group like this:

After you run the script and get your first notification, you’ll see that it comes through like this:

Pretty easy! Now, let’s look at the SQL server and understand the other options you have available to change. I’ll use another example to illustrate how this works.

Auto Update License

This can be done other ways, but it’s a simple value that should be easy to update.

  1. Update SQL Server Management Studio, login and expand your VeeamBackup database.
  2. Navigate to dbo.Options, right-click and choose “Select Top 1000 Rows”.
  3. Scroll down to where you’ll see AutoUpdateLicense.

The following SQL query would change this from True to False:

UPDATE 
    dbo.Options
SET 
    value.modify('replace value of (/text())[1] with "True"')
WHERE
    name = 'AutoUpdateLicense';

After running this, you’ll see the value update to “True”. Since this was my first time editing XML with SQL, I want to walk through how these lines get created so you can do this on your own:

  1. Line 2 is the name of the table we’re editing.
  2. Line 4 is saying value.modify because the column’s name is value and we’re modifying the XML.
  3. After “replace value of”, we have the first forward slash telling us we’re updating the root of the document, much like the root of a drive. text() is telling SQL what datatype we’re updating it to. If you look under email_notifications, you’ll see that there is a full object in there, rather than just a single line of text. That’s why we had /CMailOptions/Subject/text() rather than just /text().
  4. Then, we have [1], which is telling SQL to update the first document in the array.
  5. Lastly, our WHERE query just tells us which row in dbo.Options we’re updating.

Closing

I hope this saves someone a bit of time in the future. In the future, I hope to write about replacing credentials and in my next post, showing everyone how we used this to update our notifications, send them to Power Automate, and create a low-cost BackupRadar replacement.

Related Posts