I'm trying to use PowerShell to create a backup policy for use with Windows Server Backup on Windows Server 2008 R2. I've written the following test script to make sure everything is working. I've been able to confirm that my script is correct, but I'm receiving an error message from the final command. Here is my script:
Add-PsSnapin Windows.ServerBackup$Policy = New-WBPolicy
Set-WBSchedule -Policy $Policy -Schedule 10:30
$BackupDir = New-WBFileSpec -FileSpec C:\inetpub\Websites
Add-WBFileSpec -Policy $Policy -FileSpec $BackupDir
$SecPassword = ConvertTo-SecureString "************" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential("BackupUserAccount", $SecPassword)
$BackupNetworkTarget = New-WBBackupTarget -NetworkPath "\\Backup1\Backup$\Web Backups\Bills Khakis" -Credential $Credentials
Add-WBBackupTarget -Policy $Policy -Target $BackupNetworkTarget
Set-WBPolicy -Policy $Policy
I've changed the username and password in this posting, but everything else is being input as-is. None of the commands throw an error except for the last one. After the last command is issued, the server pauses for a moment (I'm assuming it's trying to contact the destination server) and the comes back with the following error message:
Set-WBPolicy : The credentials entered are either incorrect or do not have write permissions to the remote shared folder. Please specify valid credentials.At line:1 char:13
+ Set-WBPolicy <<<< -Policy $Policy
+ CategoryInfo : NotSpecified: (:) [Set-WBPolicy], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Windows.ServerBackup.Commands.SetWBPolicy
The obvious answer is to say, the username and password are wrong. However, I have checked and re-checked the credentials and they are correct. I am able to access that share using the username and password that are in the script. So what's going on? Any ideas?