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
Product Manager
Posts: 14314
Liked: 2890 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
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
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
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
Veteran
Posts: 1143
Liked: 302 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: 1918
Liked: 636 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
chengeel
Lurker
Posts: 2
Liked: never
Joined: Mar 14, 2024 3:39 am
Contact:

Re: Powershell script for file restores

Post by chengeel »

Hi,

I test above script... but getting this error

Add-PSSnapin : The Windows PowerShell snap-in 'VeeamPSSnapin' is not installed on this computer.
At C:\Scripts\RestoreTest.ps1:1 char:1
+ Add-PSSnapin VeeamPSSnapin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Mildur
Product Manager
Posts: 8678
Liked: 2275 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Powershell script for file restores

Post by Mildur »

Hi Chengeel

VeeamPSSnapin was removed in version 11. It is not required anymore.
Does the script work if you remove the line "Add-PSSnapin VeeamPSSnapin"?

Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests