5

I wrote the following Powershell Script to perform a one time backup of my Windows Server 2008 R2 machine. The idea is to perform a Weekly backup to a different external drive and schedule the script to run from Task Scheduler.

Import-Module ServerManager
Add-PSSnapin Windows.ServerBackup

$backup = Get-WBPolicy
$weekly = New-WBPolicy

Add-WBVolume -POLICY $weekly -VOLUME $backup.VolumesToBackup

$inc1 = NEW-WBFileSpec -FileSpec "C:\"
$inc2 = NEW-WBFileSpec -FileSpec "D:\"
$incs = $inc1,$inc2
Add-WBFileSpec -POLICY $weekly -fileSpec $incs

$disk = WBDisk | where{$_.DiskName -EQ "Seagate Backup+ Desk USB Device"}
$target = New-WBBackupTarget -DISK $disk
Add-WBBackupTarget -POLICY $weekly -TARGET $target

Add-WBBareMetalRecovery -POLICY $weekly
Set-WBVSSBackupOptions -POLICY $weekly -VSSFULLBACKUP

Start-WBBackup -POLICY $weekly

I get the following error:

Start-WBBackup : Object reference not set to an instance of an object.
At C:\Users\ejb\Documents\Scripts\WeeklyBackup.ps1:21 char:15
+ Start-WBBackup <<<<  -POLICY $weekly
    + CategoryInfo          : NotSpecified: (:) [Start-WBBackup], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.Windows.ServerBackup.Commands.StartWBBackup

I checked and verified that all the proper modules, snapins and features were installed/loaded.

3
  • If you debug it, what's the state of $weekly object when you get to (just before) the Start-WBBackup line (21)? It seems to be saying it's NULL. If it's not NULL are all (required) properties set as expected in that object? Dec 11, 2013 at 17:18
  • 1
    Yes. I placed a breakpoint in the ISE before the Start command is executed and $weekly variable has this value: Schedule : BackupTargets : {Seagate Backup+ Desk USB Device} VolumesToBackup : {DATAPART1 (D:), Local disk (C:)} FilesSpecsToBackup : {C:\*, D:\*} FilesSpecsToExclude : {} BMR : True SystemState : False VssBackupOptions : VssFullBackup I checked MSDN and schedule does not need to be set for this case. Dec 11, 2013 at 17:39
  • Can you Start-WBBackup manually?
    – ernie
    Dec 11, 2013 at 19:29

2 Answers 2

2

I found that the problem was being caused by the way I was setting the target. Even though it was showing correctly set, it was not bound correctly to the WBPolicy I was making. The correct way to set the target was:

$disk = New-WBBackupTarget -VolumePath G:
Add-WBBackupTarget -POLICY $backup -TARGET $disk

Although this assumes that the disk attached is always mounted to the G: letter, it worked successfully when I ran it.

0

I am having same problem when defining onetime backup (or generating Policy on-the-fly). I think... You have to use Volume (object from Get-WBVolume) or VolumePath (if mount letter is available). Disk options is there when you want to define persistent policy. When you use Disk (object from Get-WBDisk), you have to use Set-Policy and disk will be cleared and new volume will be created on it. That volume will be then used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .