PowerShell script exchange
Post Reply
sebastien MULOT
Novice
Posts: 7
Liked: never
Joined: Nov 15, 2021 10:31 am
Contact:

automate the restoration of a disk to another VM

Post by sebastien MULOT »

Case #05818974

Hello,
I want to restore the data disk E: from the production VM xxx-SQL to a test VM xxx-SQL-TEST every day.
I found how to do it from the Veeam console but I would like to automate the task with a script.
https://helpcenter.veeam.com/docs/backu ... ml?ver=110

I found some commands but I don't know how to select the E: disk and restore it to the xxx-SQL-TEST VM

https://helpcenter.veeam.com/docs/backu ... ml?ver=110

Code: Select all

$backup = Get-VBRBackup -Name "Backup Job Vm Appl et DB"
$restorepoint = Get-VBRRestorePoint -Backup $backup
$disks = Get-VBRViVirtualDevice -RestorePoint $restorepoint[3]
$mappingrule = New-VBRViVirtualDeviceMappingRule -SourceVirtualDevice $disks
Start-VBRViVirtualDiskRestore -RestorePoint $restorepoint -VirtualDeviceMapping $mappingrule
Thanks for your help
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: automate the restoration of a disk to another VM

Post by oleg.feoktistov »

Hi,

You mean you want to find a way to correlate disk label with vSphere disk info that gets references when using Get-VBRViVirtualDevice? If that's the case, I don't think we query that data on VBR side from vSphere. What you could do is use PowerCLI to get disk labels:

Code: Select all

$vm = Get-VM -Name 'VM'
$disk = Get-HardDisk -VM $vm
$disk.Parent.Guest.Disks
Thanks,
Oleg
sebastien MULOT
Novice
Posts: 7
Liked: never
Joined: Nov 15, 2021 10:31 am
Contact:

Re: automate the restoration of a disk to another VM

Post by sebastien MULOT »

Hello,
I try to do the Powershell commands from the SQL VM but I get an error message:
"Get-VM You are not currently connected to any servers. Please connect first using a connect cmdlet"
I need to be connected to the Vcenter to run the commands and the script should contain the user and password for it to run automatically.
I could make an encrypted file to store the user and password but I don't know how to do it.

Thanks for your help but I don't have enough knowledge to do this job.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: automate the restoration of a disk to another VM

Post by oleg.feoktistov »

Hi,

Please consult VMware PowerCLI official guide for that. You'll especially need Managing vSphere with VMware PowerCLI part.
For encryption part try CredentialManager module. It saves your creds in Windows Credential Manager in a type acceptable by PowerCLI cmdlets.

Best regards,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests