Backup with PowerShell in Windows 2012


1 Open an elevated PowerShell window. (You must be a member of either the Administrators or Backup Operators group to perform these steps.)

2 Configure your script execution policy to allow untrusted scripts by typing the following and choosing Yes when prompted:

Set-ExecutionPolicy Unrestricted

3 Now input the following PowerShell script while making sure to change the values for New-WBBackupTarget and Get-WBVirtualMachine to something that’s relevant to your own environment:

# Create a New Backup Policy

$BackupPolicy = New-WBPolicy

# Specify a Target

$BackupTarget = New-WBBackupTarget -VolumePath F:

# Add the target to your policy

Add-WBBackupTarget -Policy $BackupPolicy -Target $BackupTarget

# Specify your virtual machine name

$VMs = Get-WBVirtualMachine | where vmname -like “ws2012r2*”

Add-WBVirtualMachine -Policy $BackupPolicy -VirtualMachine $VMs

# Configure the schedule

$BackupTime = [datetime] “23:00”

Set-WBSchedule -Policy $BackupPolicy -Schedule $BackupTime

# Activate the policy

Set-WBPolicy -Policy $BackupPolicy -AllowDeleteOldBackups

4 Once the script runs, your backup policy will be confi gured to run at the scheduled time, and you can view the job from inside the Windows Server Backup console.


Comments are closed.

(adsbygoogle = window.adsbygoogle || []).push({}); //--> Feedjit Flag Counter