PowerShell script exchange
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Feb 26, 2026 9:04 am
this post
Hi All,
We have below automation requirements. Please suggest
Requirements:
Automate VM disk level restore from one server to another server (both are linux servers)
get the scsi id from source server
restore that disk to the target server with specific scsi id always (ex: source scsi id 0:3 adn target scsi id 0:2 always
My analysis:
using Start-VBRRestoreVirtualDisks
Below commands are to get restore points
$backup = Get-VBRBackup -Name "Backup Job name"
$restorepoint = Get-VBRRestorePoint -Backup $backup
how to get the scsi id of source server and restore it in the specific scsi id of target server?
Regards,
Surya
david.domask
Product Manager
Posts: 3433 Liked: 819 times
Joined: Jun 28, 2016 12:12 pm
Contact:
Post
by david.domask » Feb 26, 2026 9:16 am
1 person likes this post
Hi Surya,
I've moved your topic to our PowerShell forums as looks like you're looking to do this with PowerShell.
Please see the examples for
Start-VBRViInstantVmDiskRecovery , it walks you through the workflow for doing an instant disk recovery to a target machine.
Once done, you can
migrate the disks to production and the restored disk will be persisted to the target VM.
David Domask | Product Management: Principal Analyst
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Feb 26, 2026 10:09 am
this post
Hi David,
Thanks for your reply.
Can't we do it using "Start-VBRViVirtualDiskRestore" and New-VBRViVirtualDeviceMappingRule
Regards,
Surya
david.domask
Product Manager
Posts: 3433 Liked: 819 times
Joined: Jun 28, 2016 12:12 pm
Contact:
Post
by david.domask » Feb 26, 2026 11:05 am
1 person likes this post
Happy to help, Surya.
Yes, Start-VBRViVirtualDiskRestore can help here, but it doesn't support setting the target device node.
Start-VBRViInstantVmDiskRecovery let's you set the TargetVirtualDevice, and it will attach exactly as you desire in your original post, and the only additional step is to migrate the disks to production as noted in my earlier post.
I think this will better match your written needs.
David Domask | Product Management: Principal Analyst
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Feb 26, 2026 11:27 am
this post
Hi David,
Thanks.
Can we attach to the existing virtual device (scsi id) using Start-VBRViInstantVmDiskRecovery?
Can u help in scripting?
example:
source vm= server1
source scsi ids= 0:3, 0:4
target vm= server2
target scsi ids= 0:2, 0:3
Code: Select all
================instant disk recovery================
$backup = Get-VBRBackup -Name "server1"
$restorepoint = Get-VBRRestorePoint
$targetserver = Get-VBRServer -Name "server2"
$device = Get-VBRViVirtualDevice -RestorePoint $restorepoint[3]
Start-VBRViInstantVMDiskRecovery -RestorePoint $restorepoint[3] -TargetVM $targetserver -TargetVirtualDevice $device
====================InstantRecoveryDiskMigration==============
$sesson = Get-VBRInstantRecovery
$backup = Get-VBRBackup -Name "server2"
$restorepoint = Get-VBRRestorePoint -Backup $backup
$disks = Get-VBRViVirtualDevice -RestorePoint $restorepoint[3]
$mapping = New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $disks
Start-VBRViInstantRecoveryDiskMigration -InstantRecovery $sesson -DiskMigrationMappingRule $mapping -Force -RunAsync
===============================================
Regards,
Surya
david.domask
Product Manager
Posts: 3433 Liked: 819 times
Joined: Jun 28, 2016 12:12 pm
Contact:
Post
by david.domask » Feb 26, 2026 12:47 pm
1 person likes this post
You have it mostly correct, but on your Start-VbrViInstantDiskRecovery, you need to include the
TargetVirtualDevice flag as I linked above.
You fetch the source with Get-VBRViVirtualDevice, then use
Set-VbrViVirtualDevice and set the disk settings as desired. Save the changes with Set-VbrViVirtualDevice to a variable, and pass that on the TargetVirtualDevice parameter of Start-VbrViInstantDiskRecovery.
As you have it now, it will use the device mappings from the source VM as it is in the backup.
David Domask | Product Management: Principal Analyst
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Feb 26, 2026 2:45 pm
1 person likes this post
below script is working for me
Code: Select all
$backup = Get-VBRBackup -Name "job name"
$restorepoint = Get-VBRRestorePoint -Backup $backup
$disks = Get-VBRViVirtualDevice -RestorePoint $restorepoint[1] | Where-Object {$_.Name -eq "server_1.vmdk"}
$server = Get-VBRServer -Name "esxihost"
$vm = Find-VBRViEntity -Server $server -Name "server2"
$device=Set-VBRViVirtualDevice -VirtualDevice $disks -ControllerNumber 0 -Type SCSI -VirtualDeviceNode 3
Start-VBRViInstantVMDiskRecovery -RestorePoint $restorepoint[1] -TargetVM $vm -TargetVirtualDevice $device
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Mar 18, 2026 3:27 pm
this post
our code
Approach: 3 disk restore to another server ( we cannot change the target scsi id in Start-VBRViVirtualDiskRestore )
Code: Select all
#Variables
$sourcejob = "job1"
$sourcevm = "server1"
$destinationvm ="server2"
$destvcenter = "esxi host"
$destdatastore = "datastore
# 1. Get the backup
$backup = Get-VBRBackup -Name $sourcejob
# 2. Get latest restore point for VM
$rp = Get-VBRRestorePoint -Backup $backup |
Where-Object {$_.VmName -eq $sourcevm} |
Sort-Object CreationTime -Descending |
Select-Object -First 1
# 3. Get virtual disks attached to that RP
$disks = Get-VBRViVirtualDevice -RestorePoint $rp
# 4. Map by controller + node, target scsi id will be same as source id
$disk_02 = $disks | Where-Object { $_.ControllerNumber -eq 0 -and $_.VirtualDeviceNode -eq 2 }
$disk_03 = $disks | Where-Object { $_.ControllerNumber -eq 0 -and $_.VirtualDeviceNode -eq 3 }
$disk_04 = $disks | Where-Object { $_.ControllerNumber -eq 0 -and $_.VirtualDeviceNode -eq 4 }
# 4. Datastore on target vCenter
$server_dst_ds = Get-VBRServer -Name $destvcenter
$datastore = Find-VBRViDatastore -Server $server_dst_ds -Name $destdatastore
# 5. Build mapping rules with Datastore
$rule1 = New-VBRViVirtualDeviceMappingRule -SourceVirtualDevice $disk_02 -Datastore $datastore
$rule2 = New-VBRViVirtualDeviceMappingRule -SourceVirtualDevice $disk_03 -Datastore $datastore
$rule3 = New-VBRViVirtualDeviceMappingRule -SourceVirtualDevice $disk_04 -Datastore $datastore
$mappingrules = $rule1, $rule2, $rule3
# 6. Target VM (on another vCenter)
$server_dst_vm = Get-VBRServer -Name $destvcenter
$vm = Find-VBRViEntity -Server $server_dst_vm -Name $destinationvm
# 7. Start the disk level recovery
Start-VBRViVirtualDiskRestore `
-RestorePoint $rp `
-TargetVM $vm `
-VirtualDeviceMapping $mappingrules `
-PowerOn `
-Force
Suryanarayanan
Enthusiast
Posts: 38 Liked: 6 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:
Post
by Suryanarayanan » Mar 18, 2026 3:31 pm
this post
approach: using "Start-VBRViInstantRecoveryDiskMigration" , can change the target scsi id
# 1. Get the backup
Code: Select all
$backup = Get-VBRBackup -Name "job1"
# 2. Get restore points
Code: Select all
$restorepoint = Get-VBRRestorePoint -Backup $backup | Where-Object {$_.VmName -eq "server1"}|Sort-Object CreationTime -Descending| Select-Object -First 1
$rp = $restorepoint[0]
$disks = Get-VBRViVirtualDevice -RestorePoint $restorepoint[0]
$server = Get-VBRServer -Name "esxihost"
$vm = Find-VBRViEntity -Server $server -Name "server2"
$devices = @()
$devices += ,( Set-VBRViVirtualDevice -VirtualDevice $disks[0] -ControllerNumber 0 -Type SCSI -VirtualDeviceNode 2 )
$devices += ,( Set-VBRViVirtualDevice -VirtualDevice $disks[1] -ControllerNumber 0 -Type SCSI -VirtualDeviceNode 4 )
$devices += ,( Set-VBRViVirtualDevice -VirtualDevice $disks[3] -ControllerNumber 0 -Type SCSI -VirtualDeviceNode 3 )
Start-VBRViInstantVMDiskRecovery -RestorePoint $restorepoint[0] -TargetVM $vm -TargetVirtualDevice $devices -Force
$session = Get-VBRInstantRecovery
$server = Get-VBRServer -Name "esxi host"
$datastore = Find-VBRViDatastore -Server $server -Name "datastore"
$rules = @()
$rules += New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $devices[0] -Datastore $datastore
$rules += New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $devices[1] -Datastore $datastore
$rules += New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $devices[2] -Datastore $datastore
$rules = foreach ($dev in $devices) {
New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $dev -Datastore $datastore
}
$mapping = New-VBRViDiskMigrationMappingRule -TargetVirtualDevice $rules -Datastore $datastore
Start-VBRViInstantRecoveryDiskMigration -InstantRecovery $session -DiskMigrationMappingRule $mapping -Force -RunAsync
Users browsing this forum: No registered users and 1 guest