Skip to content
Luca Dell'Oca Principal Cloud Architect @Veeam
Virtual To The Core Virtual To The Core

Virtualization blog, the italian way.

  • Media
  • About me
Virtual To The Core
Virtual To The Core

Virtualization blog, the italian way.

Automatically create Veeam backups using vCenter Moref IDs

Luca Dell'Oca, August 23, 2017August 22, 2017
For a project I’m working on these weeks, I’ve been asked to demonstrate how an external system (a Cloud Management Platform, an Automation tool, else) can automatically create backups for some specific virtual machines without interacting with the Veeam console. This blog post will show you how, using vSphere Moref IDs.

The ingredients

vCenter and Veeam use the same common field to uniquely identify a virtual machine, and this is the MorefID. This value is assigned by vCenter to every object that is created in its hierarchy, and it’s unique and unchanged for as long as the object itself is registered in vCenter. Veeam uses the same ID to identify which virtual machine needs to be backed up. So, definitely, this ID is our starting point.
Second, both platforms can use Powershell to automate many operations; in our case, we want to retrieve the MorefID of a given VM and pass this value as a parameter to Veeam Backup & Replication. If we want to use a dedicated windows machine to run our scripts (since Powershell runs on Windows), this machine, first of all, needs to have both Powershell modules installed.
Powershell 5.0 has an option to install additional modules using the Gallery, a public repository accessible over the Internet where we can retrieve and install supported modules directly from the shell itself, as long as the machine has Internet connectivity. My machine is running Windows 2012 R2, so it has Powershell 4.0 by default, not 5.0; however, we can easily upgrade it to the latest version, and there are many blog posts that show you how to do it. Once Powershell is upgraded to 5.0, we can just run:
Install-Module -Name VMware.PowerCLI

The command will require additional steps like to install dependencies and so on, but the final result is that the PowerCLI module is installed in our machine and ready to be used.

Veeam Backup & Replication Powershell is available as a snap-in, not as a module, so we need to install it locally; this can be done by installing the Standalone Console, as the PowerShell snap-in is part of its installation. We will then load it inside the script when we will run it, using as always this line:
asnp VeeamPssnapin

We are ready to build our proof of concept.

The script

Premise: I’m not a developer, and I only needed this small test to demonstrate that all this automation was doable, so forgive my low-level PowerShell skills; my code works, but probably many can make it better.
First of all, we need to retrieve the Virtual Machine MorefID. This can be done using this command:
$vmname = Read-Host "What is the name of the VM?"
$tempvm = Get-VM -Name $vmname
$morefid = $tempvm.ExtensionData.MoRef.Value

where we ask the user to tell us which VM he wants to protect. In my example, I’m going to protect one of my domain controllers, and if I input “dc1” in the dialog, the result is this:

So, now I have the MorefID stored in a variable. It’s now time to pass this information to Veeam; this can be done in a few lines of codes, and the final script would be this one:
# Connect to vCenter
$vcenter = "vcsa.cloudconnect.local"
Connect-VIServer $vcenter
 
# Ask for the VM to protect
$vmname = Read-Host "What is the name of the VM?"
Write-Host "We are creating a new backup for virtual machine $vmname"
 
# Find the MorefID of the VM
$tempvm = Get-VM -Name $vmname
$morefid = $tempvm.ExtensionData.MoRef.Value
 
# Load Veeam snap-in
asnp VeeamPssnapin
 
# In Veeam, connect to vCenter and identify the same VM
$vc = Get-VBRServer -name $vcenter
$VM = Find-VBRViEntity -Server $vc | where {$_.Reference -eq $morefid}
 
# Create a new backup for the VM
Add-VBRViBackupJob -Name $morefid -Entity $VM

and this is the script in action:

I’ve cut the output, as there are many more information in regards to the new backup job that has just been created; all the options like scheduling, guest processing and so on can be configured using more parameters of Add-VBRViBackupJob or other Veeam Powershell commands. My goal here was to show that a new backup job has been created in Veeam (and you can notice that in the description it says “Created by Powershell”):
Also, the MorefID is used as the name of the job. Then, if we look at the list of Virtual Machines, we can see that dc1 is the only virtual machine that is going to be protected by the new job:
People can further customize the script in order to have automatic configuration of schedule, datastore selection, and many other options. But the main goal of automatically creating a backup from just the MorefID has been accomplished.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
Tech automationbackupIDmorefpowerclipowershellvcenterveeamvsphere

Post navigation

Previous post
Next post

Search

Sponsors

Latest Posts

  • Migrate WSL (Windows Subsystem for Linux) to a new computer
  • Pass keystrokes to a pfSense virtual machine to install it automatically
  • Automatically deploy pfSense with Terraform and Ansible
  • My Automated Lab project: #6 Create a S3 Bucket with Terraform
  • My Automated Lab project: #5 Deploy a Linux vSphere VM with Terraform and custom disks
©2025 Virtual To The Core | WordPress Theme by SuperbThemes
We use cookies to ensure that we give you the best experience on our website, and to collect anonymous data regarding navigations stats using 3rd party plugins; they all adhere to the EU Privacy Laws. If you continue to use this site we will assume that you are ok with it.OkNoPrivacy Policy