PowerShell script exchange
Post Reply
goldleader80
Influencer
Posts: 10
Liked: never
Joined: Mar 20, 2012 8:50 am
Contact:

Schedule Restores

Post by goldleader80 »

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
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: Schedule Restores

Post by Martin9700 »

Looks like you misspelled the word FALSE :)
Martin
www.thesurlyadmin.com
@thesurlyadm1n
goldleader80
Influencer
Posts: 10
Liked: never
Joined: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: Schedule Restores

Post by Martin9700 »

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
goldleader80
Influencer
Posts: 10
Liked: never
Joined: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: Schedule Restores

Post by Martin9700 »

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
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Schedule Restores

Post by veremin »

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.
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: Schedule Restores

Post by Martin9700 »

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
goldleader80
Influencer
Posts: 10
Liked: never
Joined: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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?
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Schedule Restores

Post by veremin »

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.
goldleader80
Influencer
Posts: 10
Liked: never
Joined: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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: Mar 20, 2012 8:50 am
Contact:

Re: Schedule Restores

Post by goldleader80 »

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

Thanks for all the help
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: Schedule Restores

Post by Martin9700 »

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
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 5 guests