question

l0wBoB avatar image
0 Votes"
l0wBoB asked l0wBoB commented

Set up Windows Server Backup via PowerShell

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?

windows-server-powershellwindows-server-hyper-vwindows-server-backup
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered l0wBoB commented

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.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Rich,

yes, I'm trying to use Set-WBPolicy immediately after line 19.
Get-WBPolicy -Editable returns nothing, most likely because no Policy was successfully saved yet.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered l0wBoB commented

Hello @l0wBoB

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

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

Hope this helps,
Best regards,

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey,
unfortunately, the existence of the Verbose parameter doesn't change the overall outcome.
If it's there, it just informs the user that they are about to change the scheduled backup for the Windows Server Backup before displaying the error.
I just added it in hopes of getting further information which parameter is supposedly wrong.

0 Votes 0 ·