PowerShell script exchange
Post Reply
bigmaneric97
Novice
Posts: 5
Liked: never
Joined: Jul 21, 2020 1:00 pm
Full Name: Eric Speake
Contact:

Script to restore a VM through powershell

Post by bigmaneric97 »

I have a VM that I need to schedule a restore each day. This is what I have tested with, but I'm not sure of how to get the the COib the documentation calls for.

Code: Select all

PS C:\Users\esa> $backup = Get-VBRRestorePoint -Name EntreLiteDemo 
PS C:\Users\esa> echo $backup

VM Name                   Creation Time          Type
-------                   -------------          ----
EntreLiteDemo             7/6/2020 2:24:28 PM    Full
EntreLiteDemo             7/6/2020 2:50:05 PM    Increment
EntreLiteDemo             7/6/2020 3:05:11 PM    Increment
EntreLiteDemo             7/20/2020 4:49:30 PM   Increment


PS C:\Users\esa> Start-VBRRestoreVM _RestorePoint $backup -Reason "Test Restore" -ToOriginalLocation -StoragePolicyActio n Default 
Start-VBRRestoreVM : Cannot bind parameter 'RestorePoint'. Cannot convert the "_RestorePoint" value of type "System.String" to type "Veeam.Backup.Core.COib".
At line:1 char:20
+ Start-VBRRestoreVM _RestorePoint $backup -Reason "Test Restore" -ToOriginalLocat ...
+                    ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-VBRRestoreVM], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.StartVBRRestoreVM
I appreciate the help.

Eric
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Script to restore a VM through powershell

Post by jhoughes » 1 person likes this post

You need to specify a single restore point to start the recovery, not give it the full array of restore points.

Examples #2 & 3 of the documentation show the selection of a single restore point.

Otherwise, you could do this for the latest point (only inserted line 2 to your existing code and updated variable in line 3):

Code: Select all

$backup = Get-VBRRestorePoint -Name EntreLiteDemo
$latest = $backup | sort creationtime -Descending | select -first 1
Start-VBRRestoreVM -RestorePoint $latest -Reason "Test Restore" -ToOriginalLocation -StoragePolicyAction Default 
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
bigmaneric97
Novice
Posts: 5
Liked: never
Joined: Jul 21, 2020 1:00 pm
Full Name: Eric Speake
Contact:

Re: Script to restore a VM through powershell

Post by bigmaneric97 »

@jhoughes Thank you so much. That makes it all work.

Eric
bigmaneric97
Novice
Posts: 5
Liked: never
Joined: Jul 21, 2020 1:00 pm
Full Name: Eric Speake
Contact:

Re: Script to restore a VM through powershell

Post by bigmaneric97 »

Is there a command that will require the existing files to be deleted and then restored? And is there a command that restart the VM after restoration? I'm trying to fins these commands and I have not had much luck.

Thank you.
Eric
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Script to restore a VM through powershell

Post by veremin »

You mean the command that will physically remove files of original VM prior to restore process? No such command in Veeam PowerShell Snap-in, but you can remove VM, using VMware PowerCLI. You can restart VM as well. Thanks!
bigmaneric97
Novice
Posts: 5
Liked: never
Joined: Jul 21, 2020 1:00 pm
Full Name: Eric Speake
Contact:

Re: Script to restore a VM through powershell

Post by bigmaneric97 »

Thanks. I found the StartUp switch. so I will try that. I get a failure on disk space on the attempt to restore. Works on the second attempt. I may have to switch datastores.

Thanks,
Eric
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Script to restore a VM through powershell

Post by veremin »

The situation does not look expected, so, I would reach our support team first to resolve the restore issue before digging deeper into scripting. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests