Using Windows Task Scheduler to Launch Veeam PowerShell

Veeam Backup and Replication provides a PowerShell scripting environment to help administrators manage their Veeam installation. Veeam Backup Powershell SDK as it is known is a PowerShell snap-in. You’ve probably seen it as an option that is available but not automatically selected by the setup program; so if you miss it at installation time, just find the installer (.msi) in the product image .iso file and install it from there. Running commands in the PowerShell command window or the ISE is fairly straightforward but I was looking for a way that I could use the Windows Task Scheduler to fire off a PowerShell script. Here’s my story.

As I mentioned you can run the Veeam commands interactively in the command window or create scripts that you can invoke in the command window. You can launch the Veeam Backup PowerShell SDK from the Backup and Replication (B&R) console using the Home dropdown and clicking on the PowerShell blue icon. Patience, it takes a while to launch. In a minute or so, the PowerShell command window opens and you can run commands or scripts.

But what if you just want to run a script from a Command window or in my case from a scheduled task. What do you do? If you try to invoke a script containing Veeam Backup PowerShell SDK commandlets like this “powershell -file yada-yada.ps1”, it will fail. If you use the that command in Task Scheduler, it will fail as well.

The Veeam documentation does an excellent job of describing the tool. There are almost 700 pages in the manual but it relies on external documentation to tell you how to leverage PowerShell for your own use. Veeam also has a huge disclaimer that it will not help you create scripts. Seems fair. OK, I’m busy and I’m not a PowerShell expert. All I want to do is schedule a script to run periodically.

My need came about as a result of trying to leverage the SureBackup functionality. SureBackup provides an isolated environment to test recovery of Veeam backups by allowing the VMs to boot up and run in an isolated network separate from your production environment. The isolated network is “contained” in a “Virtual Lab”. How cool! Really! You can also leverage the Virtual Lab to allow developers to make changes to VMs in the lab environment and test out functionality. An immediate example would allow you to bring up an isolated environment with key virtual machines that you could apply Microsoft patches to test out functionality prior to rolling them to your production environment.

My B&R server was not on the same VLAN as the VMWare host environment – it needs to be. Since we’re not going to move the B&R server, the easiest way around this is to deploy another B&R server to perform SureBackup and host the virtual labs. You can only have one B&R server control the Veeam Backup and Replication environment. But you can have another B&R server on the VMware VLAN control SureBackup. That’s what I did. All SureBackup is run on the B&R server in the VMWare environment.

So, what’s the problem. Simple, Once the jobs are set up and the applications defined in the SureBackup Application Groups, you need a way to keep the repository contents synchronized. You can Rescan a repository in the console to update B&R manually. You can also leverage the SYNC-VBRBackupRepository commandlet in a Veeam Powershell command window to do the same thing.

How do you automate this? Here’s what I did.

Create a PowerShell script. Mine is shown below. Call the file “Rescan.ps1”.

SYNC-VBRBackupRepository -Repository “REPO_PY21”
SYNC-VBRBackupRepository -Repository “REPO_PY21a”
SYNC-VBRBackupRepository -Repository “REPO_PY22”
SYNC-VBRBackupRepository -Repository “REPO_PY22a”
SYNC-VBRBackupRepository -Repository “REPO_PY23”
SYNC-VBRBackupRepository -Repository “REPO_PY23a”
SYNC-VBRBackupRepository -Repository “REPO_PY24”
SYNC-VBRBackupRepository -Repository “REPO_PY24a”

You can run this in the command window launched from the B&R console and it works fine. Try to create a Windows Scheduled Task with the command “powershell.exe -file “C:\Scripts\Rescan.ps1” and it will fail.

What’s missing? The following commandlet: “Add-PSSnapin -Name VeeamPSSnapin.” Add this line to the beginning of your script file and everything works. When the B&R console launches the PowerShell environment, it adds its snap-in automatically. You don’t see this and I haven’t found this in their documentation. I did as Mr. Google and got a lot of hits on using the Veeam commandlets to schedule jobs but that was not what I wanted to do. Finally, I was able to discover the magic word, “VeeamPSSnapin” and connected with the PowerShell “Add-PSSnapin” commandlet to get this to work.

Conclusion: the simplest things can often burn hours of your time.

This posting is provided “as is” with no warranties, guarantees or rights whatsoever.

This entry was posted in Education, General Information, Tips and tagged , , , . Bookmark the permalink.

One Response to Using Windows Task Scheduler to Launch Veeam PowerShell

  1. Q7 says:

    Apps may use this to determine approximately where you are.

Leave a Reply

Your email address will not be published. Required fields are marked *