PowerShell script exchange
Post Reply
mattGamm
Novice
Posts: 3
Liked: 1 time
Joined: Feb 01, 2021 2:57 pm
Full Name: Matt Gammon
Contact:

Powershell script for file restores

Post by mattGamm »

Hello There,

I am trying to create a PowerShell script to restore a file from a backup job which will then run on a monthly bases to test the backups, so far have managed to create the following;

Code: Select all

Add-PSSnapin VeeamPSSnapin

$restore_point = Get-VBRBackup | Get-VBRRestorePoint -Name "SERVER" | Sort-Object –Property CreationTime –Descending | Select-Object -First 1

$restore_start = Start-VBRWindowsFileRestore -RestorePoint $restore_point -Reason "For testing purposes"

# $restore_credentials = Get-VBRCredentials -Name "DOMAIN\Admin"

$restore_session = Get-VBRRestoreSession | ?{$_.state -eq "Working" -and  $Id -eq $restore_start.MountSession.RestoreSessionInfo.Uid}

Start-VBRWindowsGuestItemRestore -Path  "C:\Scripts\" -RestorePolicy Keep -Session $restore_session

Stop-VBRWindowsFileRestore $restore_start 

But we get this error message;

Code: Select all

Start-VBRWindowsGuestItemRestore : Connection exception
At C:\Scripts\TestRestoreV3.ps1:13 char:1
+ Start-VBRWindowsGuestItemRestore -Path "C:\Scripts\" -RestorePolicy Keep -Sessio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-VBRWindowsGuestItemRestore], ConnectionException
    + FullyQualifiedErrorId : StartWindowsGuestItemRestore,Veeam.Backup.PowerShell.Cmdlets.StartVBRWindowsGuestItemRestore 
I am not sure what I am missing regarding the connection exception issue is

some of the script has come from https://developer.cisco.com/codeexchang ... tegration/

Thanks,

Matt

HannesK
Veeam Software
Posts: 8069
Liked: 1425 times
Joined: Sep 01, 2014 11:46 am
Location: Austria
Contact:

Re: Powershell script for file restores

Post by HannesK »

Hello,
and welcome to the forums.

As far as I see, you removed the credentials part. Without credentials, there is no way to log into the machine and do the file level restore.

Best regards,
Hannes

mattGamm
Novice
Posts: 3
Liked: 1 time
Joined: Feb 01, 2021 2:57 pm
Full Name: Matt Gammon
Contact:

Re: Powershell script for file restores

Post by mattGamm »

Hello,
Thank you Hannes for your reply I have added the credentials part back in now get this message;

Code: Select all

Start-VBRWindowsGuestItemRestore : Cannot validate argument on parameter 'GuestCredentials'. The argument is null. Provide a valid value for the 
argument, and then try running the command again.
At C:\Scripts\TestRestoreV3.ps1:13 char:118
+ ... estCredentials $restore_credentials
+                    ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRWindowsGuestItemRestore], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRWindowsGuestItemRestore
Thanks again,

Matt

soncscy
Veeam Legend
Posts: 396
Liked: 190 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey Carel
Contact:

Re: Powershell script for file restores

Post by soncscy »

Hi Matt,

The argument is null. Provide a valid value for the
argument, and then try running the command again.

Basically, $restore_credentials is empty -- run exactly what you put for the command in the Powershell console without trying to save it to some variable and post the output.

Would suggest that the cmdlet just couldn't find any credentials that matched the criteria you provided.

Natalia Lupacheva
Veeam Software
Posts: 725
Liked: 167 times
Joined: Apr 27, 2020 12:46 pm
Full Name: Natalia Lupacheva
Contact:

Re: Powershell script for file restores

Post by Natalia Lupacheva »

Hi Matt,

Maybe this description would help, please take a look at the example.
Did you try to add -GuestCredentials parameter as it's described?

Thanks!

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Powershell script for file restores

Post by oleg.feoktistov »

Make sure you passed CCredentials object obtained with Get-VBRCredentials and not PSCredential, which is retrieved with native cmdlet. Thanks!

mattGamm
Novice
Posts: 3
Liked: 1 time
Joined: Feb 01, 2021 2:57 pm
Full Name: Matt Gammon
Contact:

Re: Powershell script for file restores

Post by mattGamm » 1 person likes this post

Hello,

I have used the following;

Code: Select all

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

Add-PSSnapin VeeamPSSnapin

$restore_point = Get-VBRBackup | Get-VBRRestorePoint -Name "SERVER" | Sort-Object –Property CreationTime –Descending | Select-Object -First 1

$restore_start = Start-VBRWindowsFileRestore -RestorePoint $restore_point -Reason "For testing purposes"

$restore_credentials = Get-VBRCredentials -Name "Domain\VeeamServiceAccount"

$restore_session = Get-VBRRestoreSession | ?{$_.state -eq "Working" -and  $Id -eq $restore_start.MountSession.RestoreSessionInfo.Uid}

Start-VBRWindowsGuestItemRestore -Path "C:\Scripts\" -RestorePolicy Keep -Session $restore_session -GuestCredentials $restore_credentials

Stop-VBRWindowsFileRestore $restore_start
was using my Admin account but change it to use the Service Account that Veeam uses for backing up and is now working.

Thanks,

Matt

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests