Object reference not set to an instance of an object

PowerShell script exchange

Object reference not set to an instance of an object

Veeam Logoby jevao » Thu Oct 02, 2014 9:26 pm

I receive the following error when running:

Start-VBRRestoreVM -RestorePoint $RestorePoint -Server $Server -ResourcePool $ResourcePool -Datastore $vmdatastore -VMName $vmsin1

Code: Select all
Start-VBRRestoreVM : Object reference not set to an instance of an object.
At C:\users\veeam\scripts\restorebkups\restorebkups.ps1:75 char:11
+           Start-VBRRestoreVM -RestorePoint $RestorePoint -Server $Server -Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-VBRRestoreVM], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Veeam.Backup.PowerShell.Command.StartVBRRestoreVM


I used the following to set this up:

Code: Select all
 $RestorePoint = Get-VBRRestorePoint -Backup $bkup -Name $vmname-string  | sort-object $_.creationtime -Descending | select -first 1
$vmdatastore = find-vbrvidatastore -server spock.das.perforce.com -name $vmds
 $ResourcePool =  Find-VBRViResourcePool -Server (get-vbrserver -name $servername) | select -last 1
$Server = Get-vbrserver -name $servername
$vmsin1 = "vmname"

Any help would be greatly appreciated.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Object reference not set to an instance of an object

Veeam Logoby v.Eremin » Fri Oct 03, 2014 8:59 am

As first investigation step I would double check whether all variables have been assigned properly. Input variables in PowerShell console and see whether they do contain not null value.

Code: Select all
$RestorePoint
$vmdatastore
$ResourcePool
$Server
$vmsin1

Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Object reference not set to an instance of an object

Veeam Logoby jevao » Fri Oct 03, 2014 4:55 pm

Thanks for replying.
Yes I did that.
I ran it through the shell and saw the output of each was an object.
The only thing that seemed strange was "get-vbrserver -name" did not return multiple properties in the object,
but just the server name.
Other than that, if I reduce the paramaters to only mandatory parameters, Restorepoint and Server, I still see the error.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Object reference not set to an instance of an object

Veeam Logoby jevao » Fri Oct 03, 2014 5:59 pm

I was trying to restore to a cluster, not a host.
When I changed to restore directly to a host I receive the following error:

Start-VBRRestoreVM : Exception has been thrown by the target of an invocation.
At C:\users\veeam\scripts\restorebkups\restorebk.ps1:64 char:30
+ $tmpRestoreSession = Start-VBRRestoreVM -RestorePoint ($RestorePoint) -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-VBRRestoreVM], TargetInvocationException
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Veeam.Backup.PowerShell.Command.
StartVBRRestoreVM
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Object reference not set to an instance of an object

Veeam Logoby jevao » Fri Oct 03, 2014 6:08 pm

SOLVED:
The "Exception thrown" error was due to not running as Administrator.
Once I did restore from host, rather than cluster, and "Run as Administrator" on console2,
then it worked fine.
Thanks much for your help.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Object reference not set to an instance of an object

Veeam Logoby v.Eremin » Mon Oct 06, 2014 3:32 pm

Yes, that was the second question that I was going to ask - whether or nor the used account has required permissions. Glad that you've nailed it yourself. Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 10 guests