We’ve talked about Windows Server Backup feature in a previous article posted on Poweradmin blog. I’ve shown you how to install this feature and how to create and schedule Windows Server backups using the backup console. In this article I want to show you how to achieve similar results by using a Powershell script. I will try to describe each line so you can understand the logic behind it. Note that I use Windows PowerShell Integrated Scripting Environment (ISE) to create Windows scripts.
#We will start by creating a new Windows Backup(WB) policy object:
$backupPolicy = New-WBPolicy
#We will add the System State and the Bare Metal Recovery options to our new policy:
Add-WBSystemState -Policy $backupPolicy
Add-WBBareMetalRecovery -Policy $backupPolicy
#We’ll need to set a location on where the backups will be stored, I will use a local disk attached to my server. The Get-WBDisk cmdlet displays all disks attached to the server so I’ve used the $disk to specify the needed partition.
$disk = Get-WBDisk
$backupTarget = New-WBBackupTarget -Disk $disk
Add-WBBackupTarget -Policy $backupPolicy -Target $backupTarget
The script will display the backup destination disk information:
#We’ll set the Vss Full Backup option to our policy:
Set-WBVssBackupOption -Policy $backupPolicy -VssFullBackup
#The backup schedule can be configured using the Set-WBSchedule cmdlet. I’ve set the task to run everyday at 9 am:
Set-WBSchedule -Policy $backupPolicy -Schedule 09:00
#Normally, we would not be allowed to run a one-time only backup this is why we’ll have to force our policy by executing the following command:
Set-WBPolicy -force -policy $backupPolicy
#All that’s left to do is to start the backup process:
Start-WBBackup -Policy $backupPolicy
The backup will now start, Windows Powershell ISE will display a status of the backup process. You will be prompted once the the operation is completed.
You can also use the Windows Backup Console to verify the status of the backup operation. Note that the scheduled task will be configured as specified in the script (everyday at 9 am full VSS backup)
That’s about it for this script folks, hope you will enjoy it when automatizing Windows Server backup tasks. You can further develop the script to run backups for multiple machines at the same time. Note that you can also use a network share as the backup destination. Wish you all the best and stay tuned for the following articles from IT training day.