PowerShell script exchange
Post Reply
iav
Influencer
Posts: 14
Liked: 3 times
Joined: Mar 24, 2011 5:24 pm
Contact:

How to generate list of VM in backup repository?

Post by iav »

How to generate list of VM in backup repository?
Including VM already removed from vmware infrastructure, but available for restoring.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to generate list of VM in backup repository?

Post by oleg.feoktistov » 1 person likes this post

In my everyday activities I use this simple script to choose a repo and then list unique vms backed up to it:

Code: Select all

$repos = Get-VBRBackupRepository
$sobrs = Get-VBRBackupRepository -ScaleOut
$repoList = @()
foreach ($repo in $repos) {
    $repoList += $repo | select Id, Name
}

foreach ($sobr in $sobrs) {
    $repoList += $sobr | select Id, Name
}

$repoList.Name
$repoChosen = Read-Host -Prompt 'Choose repository name'
$repoChosen = $repoList | where {$_.Name -eq $repoChosen}

$backups = Get-VBRBackup | where {$_.RepositoryId -eq $repoChosen.Id}
$objectsList = @()
foreach ($backup in $backups) {
   $objects = $backup.GetObjects()
   $objectsList += $objects | select Name
}

$objectsList | sort -Unique
Hope it helps!
iav
Influencer
Posts: 14
Liked: 3 times
Joined: Mar 24, 2011 5:24 pm
Contact:

Re: How to generate list of VM in backup repository?

Post by iav »

Thank you!
nice start.
But after enter repository name, I got name of one of vm data storages.
But I need list of virtual machines from repository and job, as on screenshot below.
Image
What type of object should I look for, or what GET-??? to use, or what to iterate to get list as on a screenshot?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to generate list of VM in backup repository?

Post by oleg.feoktistov »

Hi,

Considering that the output in Powershell is plain and to present data with tree-like structure as shown on the screenshot would require some tricks, here is the closest Powershell interpretation I could think of:

Code: Select all

$backups = Get-VBRBackup
$repos = Get-VBRBackupRepository
$sobrs = Get-VBRBackupRepository -ScaleOut
$repoList = @()
foreach ($repo in $repos) {
$repoList += $repo | select Id, Name
}

foreach ($sobr in $sobrs) {
$repoList += $sobr | select Id, Name
}

foreach ($backup in $backups) {
  $targetRepo = $repoList | where {$_.Id -eq $backup.RepositoryId}
  $objects = $backup.GetObjects()
  foreach ($object in $objects) {
    $rps = Get-VBRRestorePoint -ObjectId $object.Id
    $rpFirst = $rps | sort -Property CreationTime | select -Last 1
    $object | select Name,  @{n='RPCount';e={$rps.Count}}, @{n='CreationTime';e={$rpFirst.CreationTime}}, @{n='Backup';e={$backup.Name}}, `
    @{n='Repository';e={$targetRepo.Name}}, @{n='Platform';e={$_.Platform.ToString()}} | fl
    
  }
}
Thanks,
Oleg
iav
Influencer
Posts: 14
Liked: 3 times
Joined: Mar 24, 2011 5:24 pm
Contact:

Re: How to generate list of VM in backup repository?

Post by iav » 2 people like this post

Thank you, Oleg!
My final variant:

Code: Select all

PS > Get-VBRBackup | where { $_.VmCount -gt 0 -and $_.Name -eq "offcopy"} | % { $_.Name; Get-VBRRestorePoint -Backup $_.Name | select Name -
uniq| Sort-Object {$_.Name} | % { Get-VBRRestorePoint -Name $_.Name | Sort-Object {$_.CreationTime.toString("yyyyMMddHH")} | select -First 1 } } >offc
opy-vm.txt
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests