Schedule Restores

PowerShell script exchange

Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 10:57 am

I'm looking at setting up scheduled restores using a powershell script and Task Scheduler. I'm having a little bit of trouble with the powershell script though and the VBRRestoreVM cmdlet.

First off i'm on Veeam 6.5 and the script i'm using is as follows:

Code: Select all
$rp = Get-VBRRestorePoint –Backup(Get-VBRBackup –Name “Regular #3”) –Name PRNSRV* | select –Last 1
$server = Get-VBRServer –Name "esx2"
$datast = Find-VBRViDatastore -Server $server -Name "VOL06"
Start-VBRRestoreVM -RestorePoint $rp -Server $server -Datastore $datast -VMName "PRNSRV-restore" -PowerUp FASLE


When i run this script i get the following errors:

Code: Select all
Start-VBRRestoreVM : Cannot convert 'System.String' to the type 'System.Boolean
' required by parameter 'PowerUp'.
At line:1 char:110
+ Start-VBRRestoreVM -RestorePoint $rp -Server $server -Datastore $datast -VMNa
me "PRNSRV-restore" -PowerUp <<<<  FASLE
    + CategoryInfo          : InvalidArgument: (:) [Start-VBRRestoreVM], Param
   eterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Co
   mmand.StartVBRRestoreVM


I know its something to do with the PowerUp switch but don't know what?

Also i would like to be able to tell the script which network the VM should be connected to (ie a test network) but can't seem to find a command for this.

Thanks
Edwin
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby Martin9700 » Thu Mar 07, 2013 11:02 am

Looks like you misspelled the word FALSE :)
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 11:18 am

Thanks feel very silly, sometimes you can't see the wood for the trees.

Anyway i changed my typo however i still get the same output:


Code: Select all
PS C:\Users\svcveeam> Start-VBRRestoreVM -RestorePoint $rp -Server $server -Data
store $datast -VMName "PRNSRV-restore" -PowerUp FALSE
Start-VBRRestoreVM : Cannot convert 'System.String' to the type 'System.Boolean
' required by parameter 'PowerUp'.
At line:1 char:110
+ Start-VBRRestoreVM -RestorePoint $rp -Server $server -Datastore $datast -VMNa
me "WBPRNSRV06-restore" -PowerUp <<<<  FALSE
    + CategoryInfo          : InvalidArgument: (:) [Start-VBRRestoreVM], Param
   eterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Co
   mmand.StartVBRRestoreVM
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby Martin9700 » Thu Mar 07, 2013 11:22 am

Yeah, makes sense. Should have seen that! Now try changing it to $false

And if that doesn't work we can try

-PowerUp:$false
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 11:26 am

The $false seems to have fixed the problem the job has now started. Thank you very much.

Do you have any ideas about my other problem about setting the network for the restored VM to be connected to in the script?

Thanks
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby Martin9700 » Thu Mar 07, 2013 11:38 am

I haven't used it, but it looks like Set-VMHostNetwork from the PowerCLI tools, or perhaps Set-VMHostNetworkAdapter might be the ones you need. You can look at the help to get more information:

Code: Select all
Help Set-VMHostNetwork -Full
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: Schedule Restores

Veeam Logoby v.Eremin » Thu Mar 07, 2013 11:41 am

Also i would like to be able to tell the script which network the VM should be connected to (ie a test network) but can't seem to find a command for this.

As far as I know, there is no such functionality available in VB&R PowerShell console at the moment.

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

Re: Schedule Restores

Veeam Logoby Martin9700 » Thu Mar 07, 2013 11:47 am

Yeah, can't imagine why they would try to duplicate functionality found in the VMware Powershell tools. Department of Redundancy Department kinda stuff :D
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 12:08 pm

Ok thanks for that.

Last question then i now have a .ps1 script, how would i go about executing that from within a scheduled task?

I have tested at the run command the following:

powershell -file "C:\script.ps1"

But this doesn't seem to work.

I know i can run scripts because i have set the thing a forget the name so it runs any scripts and have tested running the script from within the powershell window itself.
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 12:19 pm

Just been looking at this and i guess its because i need to load the Veeam Backup Powershell Toolkit from the command line and not just standard powershell. Anyone know how to do this?
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby v.Eremin » Thu Mar 07, 2013 12:29 pm

Just add the following line responsible for adding Veeam PowerShell Snapin to the beginning of your script:

Code: Select all
asnp VeeamPSSnapin


More information regarding script execution via Windows Scheduler can be found here.

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

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 12:47 pm

Ok i have added Add-PSSnapin VeeamPSSnapIn to my script so it now looks like this:

Code: Select all
Add-PSSnapin VeeamPSSnapIn
$rp = Get-VBRRestorePoint –Backup(Get-VBRBackup –Name “NTFS Regular #3”) –Name PRNSRV* | select –Last 1
$server = Get-VBRServer –Name "esx2"
$datast = Find-VBRViDatastore -Server $server -Name "VOL06"
Start-VBRRestoreVM -RestorePoint $rp -Server $server -Datastore $datast -VMName "PRNSRV-restore" -PowerUp $false


And if i run the cmd:

Code: Select all
powershell -file "c:\scripts\prnsrv.ps1"

A powershell window opens with nothing in, hangs for a few minutes then disappears and the job doesn't start????
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby goldleader80 » Thu Mar 07, 2013 12:54 pm

Ok figured it out. CMD needed to be ran as administrator.

Thanks for all the help
goldleader80
Influencer
 
Posts: 10
Liked: never
Joined: Tue Mar 20, 2012 8:50 am

Re: Schedule Restores

Veeam Logoby Martin9700 » Thu Mar 07, 2013 2:51 pm

I wrote a how-to on how to run Powershell as scheduled tasks, might be useful.

http://community.spiceworks.com/how_to/ ... -scheduler
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests