Cyber Security

Hyper-V: Backup VMs to a shared folder with Windows Server Backup and a Scheduled Task

Last week I had the task to backup Hyper-V VMs. No Replica, no Clustering, a simple backup with Windows Server Backup. The problem was that a repeating backup job had already been set up. Windows Server Backup allows only one job in the graphic user interface. So, the task was to create a scheduled weekly job with the command line.

I can’t stress it enough, get familiar with PowerShell. More and more extraordinary tasks can only be one in the command line. And believe me, you want to be an extraordinary guy ;-), because it’s pretty cool to make things possible where others give up and buy the next product.

Creating the Backup Job

You have to adopt the command below to your needs. Note the backup target, which is a shared folder on a NAS and the Hyper-V VMs. The quiet parameter is mandatory, because the backup job will ask if you really want to do this. What is your scheduled job in your absence supposed to answer?  😉

wbadmin start backup -backuptarget:\\\hyper-backup:"Server01,Server02" -allowDeleteOldBackups -quiet

This backups Server01 and Server02 to\hyper-backup.

Now open Notepad copy the command in a file and save this file (*.bat).


For the following make sure Windows Server Backup is installed.

Get-WindowsFeature Windows-Server-Backup


If not, hit the keys and run

Install-WindowsFeature Windows-Server-Backup -IncludeManagementTools


Creating the Scheduled Job

We are able to create a backup job either in the graphical user interface or in PowerShell. Well I think, it’s quite easier to do it in PowerShell, so I’ll show you the PowerShell code. My batch file is saved in C:\Temp\backupVM.bat. The code below creates a scheduled job that will run every Saturday at 11:00 am and is executed as sid-500\administrator. So pay attention to these values. I recommend using PowerShell ISE.

$Action=New-ScheduledTaskAction -Execute 'C:\Temp\backupVM.bat'
$Trigger=New-ScheduledTaskTrigger -Weekly -DaysOfWeek Saturday -At 11am
$Principal=New-ScheduledTaskPrincipal -UserId 'sid-500\administrator' -LogonType S4U
$Task=New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Set -Principal $Principal
Register-ScheduledTask -TaskName "Backup VM" -InputObject $Task -Force


Fine that’s it.

Windows 10 (Side Note)

I was really surprised about the presence of wbadmin on Windows 10. That means, you can also backup your VMs on Windows 10 Pro, your home lab.

See you next time with PowerShell again!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s