Hi
@wgoodall,
Glad to hear it! Though sorry that there's an issue with the restore point. Feel free to PM me the case number and I'll check in on the case.
As for a custom destination path, that's quite doable but you need to put it inside your look for the restore.
That is within:
foreach ($file in $originalFiles) {
You need to set $destPath there.
The main "issue" is you have nested ForEach loops which isn't necessarily wrong, but it can cause performance issues and you need to keep track of the variable scope. Variables are only accessible within certain scopes; each loop introduces a new scope and right now you have $destPath being set before you're looping over each restore Session/VM, so it tries to set $destPath before you've even initialized the $job variable.
I think if you set $destPath with the VMname or your desired format right after:
foreach ($file in $originalFiles) {
You should see the desired result. It will pass down to the lower loop and be accessible.
The current workflow you have is:
1. Set $originalFiles
2. Set $destPath to $job (which does not exist yet)
3. Import VM list
4. For Each VM in file, start the restore loop
5. Within the restore loop, start an FLR and mount the disks
6. Copy files from the $originalFiles path to $destPath
The problem with this workflow is that the shell has no idea what to do with steps 2 and 6. Step 2 fails because it doesn't know what $job should represent, and step 6 because $destPath is empty as a result.
Instead, you should:
1. Set $originalFiles
2. Import VM list
3. For Each VM in file, start the restore loop
4. Set $destpath at the start of the restore loop based on the VM name or Job name (your preference. VMName you have from step 2, but you can get JobName pretty easily from the $rp variable. I believe it has a BackupID Property which you can use to parse the jobs as they should also have a matching backupID property (I might be wrong on this, I'm not connected to my lab at the moment). Alternatively I'm pretty sure there's an unsupported method FindJob() on the COib objects for the $rp variable you can use to return the job and get the properties from that. See the example below.
5. Start an FLR and mount the disks
6. Copy files from the $originalFiles path to $destPath
That should work.
> 2) Is there anyway to have it restore a different restore point other than the last good backup? that would be very useful.
Sure
All COib objects (the result of Get-VBRRestorepoint) have a CreationTime property you can parse on. Figuring out which one to use might be tricky though
Programmatically, it's not complex to make Powershell take an input date and just find the closest point before/after that date. However, can I ask, do you expect someone will be at the console launching the script? If so, I would suggest a simpler option with Out-GridView where a user just picks a date from a UI launched by Powershell and it loads that point. But, if this is meant to be completely automated, then there is a bit of (semi-complex but easy to write) logic to do this.
Example:
Code: Select all
PS C:\Users\Administrator> $bois
Job Name Type Creation Time VM count
-------- ---- ------------- --------
simple-replica VMware Repli... 9/30/2022 1:24:27 AM 2
PS C:\Users\Administrator> $bois.FindJob()
Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
simple-replica VMware Repli... Stopped Success Created by DDOM-VEEAM-RB4\Administrator at 9/30/20...
PS C:\Users\Administrator> $bois.CreationTime
Friday, September 30, 2022 1:24:27 AM