Set up Windows Server Backup via PowerShell

Sebastian Billmann 1 Reputation point
2021-09-14T16:11:36.547+00:00

Hi everyone,

I'm trying to set up Windows Server Backup on a Hyper-V Server 2016 via PowerShell but always receive an error.
Here's my code:

$Policy = New-WBPolicy
Set-WBSchedule -Policy $Policy -Schedule 22:00
$Credentials = Get-Credential
$Location = New-WBBackupTarget -NetworkPath "\\NAS\Backup" -Credential $Credentials
Add-WBBackupTarget -Policy $Policy -Target $Location
$Volumes = Get-WBVolume -CriticalVolumes
Add-WBVolume -Policy $Policy -Volume $Volumes
$VHDX = New-WBFileSpec -FileSpec "C:\*.vhdx" -Exclude
$VHD = New-WBFileSpec -FileSpec "C:\*.vhd" -Exclude
$ISO = New-WBFileSpec -FileSpec "C:\*.iso" -Exclude
$Temp = New-WBFileSpec -FileSpec "C:\Windows\Temp" -Exclude
$SoftwareDistribution = New-WBFileSpec -FileSpec "C:\Windows\SoftwareDistribution" -Exclude
$catroot2 = New-WBFileSpec -FileSpec "C:\Windows\System32\catroot2" -Exclude
Add-WBFileSpec -Policy $Policy $VHDX,$VHD,$ISO,$Temp,$SoftwareDistribution,$catroot2
$VirtualMachines = Get-WBVirtualMachine
Add-WBVirtualMachine -Policy $Policy -VirtualMachine $VirtualMachines
Add-WBBareMetalRecovery -Policy $Policy
Add-WBSystemState -Policy $Policy
Set-WBVssBackupOption -Policy $Policy -VssFullBackup

The value of $Policy:

Schedule : {14.09.2021 22:00:00}
BackupTargets : {\\NAS01\Backup}
VolumesToBackup : {OS (C:)}
FilesSpecsToBackup : {}
FilesSpecsToExclude : {C:\*.vhdx, C:\*.vhd, C:\*.iso, C:\Windows\Temp\*...}
ComponentsToBackup : {VM01, VM02, Host Component}
BMR : True
SystemState : True
OverwriteOldFormatVhd : True
VssBackupOptions : VssFullBackup

If I run Start-WBBackup -Policy $Policy -Async, the backup process runs just fine and I can see the files being created in the target location.
However, if I try to apply the configuration for scheduling via Set-WBPolicy -Policy $Policy -AllowDeleteOldBackups -Verbose, the error stated is simply "wrong parameter".

Any ideas what's wrong?

Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,637 questions
Windows Server Backup
Windows Server Backup
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Backup: A duplicate copy of a program, a disk, or data, made either for archiving purposes or for safeguarding valuable files from loss should the active copy be damaged or destroyed.
465 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,906 Reputation points
    2021-09-14T18:21:55.89+00:00

    Are you using the WBPolicy you create in the same script as the Set-WBPolicy that fails?

    From the Set-WBPolicy help:

    Notes

    The WBPolicy object must be in edit mode. To put the WBPolicy object in edit mode for a policy that is set as the scheduled backup policy, use the Get-WBPolicy cmdlet with the Editable parameter. The New-WBPolicy cmdlet creates a WBPolicy object in edit mode.


  2. Limitless Technology 39,511 Reputation points
    2021-09-15T18:30:06.49+00:00

    Hello @Sebastian Billmann

    I suspect the issue is the -Verbose parameter as it is not observed in the documentation for Set-WBPolicy

    https://learn.microsoft.com/en-us/powershell/module/windowsserverbackup/set-wbpolicy?view=windowsserver2019-ps

    Hope this helps,
    Best regards,