I wonder if you can help, I need to have a script that will restore one file for every VM job to a specific folder, to test our VM backups monthly, this is currently a manual task.
Through help from this forum and some configuration changes of my own, I have put together the below script.. which works very well but is there a more elegant way to do this as I can see this script getting very cumbersome when dealing with a client with a lot of VMs.
Code: Select all
#Change VM to VMs required
$vmName = "VM1"
$vmName2 = "VM2"
$originalFiles = "C:\test"
#Change Path to match backup Job
$destPath = "C:\Veeam_Restore\TEST1\1"
$destPath2 = "C:\Veeam_Restore\TEST2\1"
# Loads the latest restore point for the servers
$result = Get-VBRBackup | Get-VBRRestorePoint | sort CreationTime -Descending | where {$_.VMName -eq "$vmName"} | select -First 1
$restore = $result | Start-VBRWindowsFileRestore
$result2 = Get-VBRBackup | Get-VBRRestorePoint | sort CreationTime -Descending | where {$_.VMName -eq "$vmName2"} | select -First 1
$restore2 = $result2 | Start-VBRWindowsFileRestore
# Copies the Files
foreach ($file in $originalFiles) {
# Find the FLR mount point for the specific drive letter
$flrmountpoint = ($restore.MountSession.MountedDevices | ? {$_.DriveLetter -eq (Split-Path $file -Qualifier)}).MountPoint
# Build the path to the file via the FLR mount point
$file = $flrmountpoint + (Split-Path $file -NoQualifier)
#Copy/Restore the files
Copy-Item $file $destPath -Force -recurse
Copy-Item $file $destPath2 -Force -recurse
}
# Stop the FLR process
Stop-VBRWindowsFileRestore $restore
Stop-VBRWindowsFileRestore $restore2
Exit
Kindest Regards
Wes