PowerShell script exchange
Post Reply
Rogue_IT
Novice
Posts: 7
Liked: never
Joined: Aug 13, 2021 5:50 pm
Contact:

Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by Rogue_IT »

I'm trying to work out how Example 3 from the PowerShell reference is supposed to work.

Code: Select all

$backup = Get-VBRBackup -Name "WinSrv25"
$restorepoint = Get-VBRRestorePoint -Backup $backup -Name "Production VM"
Start-VBRWindowsFileRestore -RestorePoint $restorepoint
$session =  Get-VBRRestoreSession
$items = Get-VBRWindowsGuestItem -Session $session -Name "Vacation"
Get-VBRWindowsGuestItem -Session $session -ParentItem $items[1] -Name "CyclingTripJuly"
There isn't a path listed, so my first assumption was that it would search the entire restore point for any folder named "Vacation" and then restore any files named "CyclingTripJuly", but that didn't seem to work when I tested it. Is there something I am misinterpreting in the example?

My end goal is to have a script that will check for a specific file on all volumes and restore it, and I would rather not have to hard code the path for each volume.
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by chris.arceneaux »

Example 3, that you referenced, doesn't fit your use case which is why it's not working as expected. That said, none of the provided examples match your use case specifically. :D

Additionally, the Path parameter is available for this cmdlet as shown in our documentation.

For your use case, it seems you don't need the path as you want to search all volumes. This is what the command looks like to search the entire restore point:

Code: Select all

$items = Get-VBRWindowsGuestItem -Session $session -Name "Vacation"
This code searches the entire restore point for any folders/files with the specified name. After retrieving the item you searched for, you can restore the it using the Start-VBRWindowsGuestItemRestore cmdlet.
Rogue_IT
Novice
Posts: 7
Liked: never
Joined: Aug 13, 2021 5:50 pm
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by Rogue_IT »

When I run it with...

Code: Select all

$items = Get-VBRWindowsGuestItem -Session $session -Name "My_File_Name"
Start-VBRWindowsGuestItemRestore -Session $session -GuestCredentials $credentials -Item $items -RestorePolicy Keep
I get...

Code: Select all

Start-VBRWindowsGuestItemRestore : Cannot validate argument on parameter 'Item'. The argument is null or 
empty. Provide an argument that is not null or empty, and then try the command again
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by chris.arceneaux »

That means your search is coming up empty. You can validate this by seeing what's contained in the $items variable:

Code: Select all

$items = Get-VBRWindowsGuestItem -Session $session -Name "My_File_Name"
$items
If your file has an extension, are you including it? i.e. "My_File_Name.pdf"
Rogue_IT
Novice
Posts: 7
Liked: never
Joined: Aug 13, 2021 5:50 pm
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by Rogue_IT »

Yes, I am including the extension.
Rogue_IT
Novice
Posts: 7
Liked: never
Joined: Aug 13, 2021 5:50 pm
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by Rogue_IT »

I believe I have solved the issue. I had flagged the file to be restored as "hidden", and it would appear that when using Get-VBRWindowsGuestItem it doesn't find hidden files or folders.
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by chris.arceneaux »

Thanks for following up! Glad to hear you got things working!

@oleg.feoktistov This is a good feature add. I see this potentially an additional flag for the cmdlet with a warning that it will increase the time required for the cmdlet to complete.
Rogue_IT
Novice
Posts: 7
Liked: never
Joined: Aug 13, 2021 5:50 pm
Contact:

Re: Confused about Get-VBRWindowsGuestItem and VBRFLRItem

Post by Rogue_IT »

After playing around with this all day, I have determined I was wrong about why it was not working, probably due to my own misunderstanding of how Get-VBRWindowsGuestItem actually works. For anyone who stumbles upon this in the future, Get-VBRWindowsGuestItem works by breaking up the file path into pieces. I ultimately just used it to grab the backed up volume letters and combined them into a path variable. This is what I ultimately developed:

Code: Select all

$restore_credentials = Get-VBRCredentials -Name "%ACCOUNT%"

$server_name = Get-VBRJob | Get-VBRJobObject -Name * | foreach { $_.Name}

foreach ($server in $server_name)
{   
	$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 "Backup File Restoration Test"

	$restore_session = Get-VBRRestoreSession | ?{$_.state -eq "Working" -and  $Id -eq $restore_start.MountSession.RestoreSessionInfo.Uid}
	
	$restore_volume = Get-VBRWindowsGuestItem -Session $restore_session | foreach {$_.Name}

    foreach ($drive_letter in $restore_volume)
    {
        $restore_file = $drive_letter + "Backup File Restoration Test\Backup_File_Restoration_Test.txt"
        
        Start-VBRWindowsGuestItemRestore -Session $restore_session -GuestCredentials $restore_credentials -Path $restore_file -RestorePolicy Keep  
    }

	Stop-VBRWindowsFileRestore -FileRestore $restore_start
}
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests