PowerShell script exchange
Post Reply
ThierryF
Expert
Posts: 129
Liked: 34 times
Joined: Mar 31, 2018 10:20 am
Contact:

Querying VBR Object Location

Post by ThierryF »

Hello,

I defined a location using add-vbrlocation cmd. Right, then assigned from GUI Location for different objects such repositories, scaleout reps, tape libs and VI Infra.

Get-VBRLocation just lists defined location.

Is it a faster way to inventory/query/list object based on location than querying location for each object ?

To obtain object location, the only way I found, for tape lib for eg, is like
foreach ($obj in Get-VBRTapeLibrary) {$loc=get-vbrlocation -object $obj ; $obj.name+" -> "+$loc.name}

Thanks
Th
Egor Yakovlev
Product Manager
Posts: 2579
Liked: 708 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: Guerying VBR Object Location

Post by Egor Yakovlev »

If you are looking for plain report to show all objects \ locations assigned, check out Veeam One Data Sovereignty Report.
/Thanks!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Querying VBR Object Location

Post by oleg.feoktistov »

Hi ThierryF,

There is no way to query it otherwise using powershell since objects resolved with get-vbrbackuprepository, get-vbrtapelibrary etc. have no Location or LocationID property within.
About your script - given that there is no way to query a list of location members directly, I would also organize output data in hashtables for better readability.
Example:

Code: Select all

$repByLocation = foreach ($obj in get-vbrbackuprepository) {get-vbrlocation -object $obj}
$repByLocation | select @{n='Component name';e={$obj.Name}}, @{n='Location';e={$_.Name}}
It would result in:

Code: Select all

Component name    Location
--------------    --------
Shared.Repository Saint.P
Shared.Repository Saint.P
All the best,
Oleg
ThierryF
Expert
Posts: 129
Liked: 34 times
Joined: Mar 31, 2018 10:20 am
Contact:

Re: Querying VBR Object Location

Post by ThierryF »

Hi,

That's the problem :
according the doc, a loc ca be set to a repository, a scaleout repository, on vmware/hyperv infa, on a tape lib, ...
As you should query location using get_vbrlocation and referencing 1 object (repository, tapelib, ...) a time,
you get powershell error if loc in unset for the object you are querying :

Let's look at this sample : repositories may have location set or not. So, let's querying it :
foreach ($BR in Get-VBRBackupRepository | sort-object -property name) {
write-host "name : ", $BR.name
$BRLOC="";$BRLOC=Get-VBRLocation -object $BR;
write-host "Physical_Location : ", $BRLOC.name, "`n";
}

output :
name : Default Backup Repository
Physical_Location : My_Location

name : IBM Spectrum Virtualize Snapshot
Get-VBRLocation : Failed to find location. Object Veeam.Backup.Core.CBackupRepository does not have any location assigned
At line:3 char:23
+ $BRLOC="";$BRLOC=Get-VBRLocation -object $BR;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VBRLocation], Exception
+ FullyQualifiedErrorId : GetLocationErrorId,Veeam.Backup.PowerShell.Cmdlets.GetVBRLocation


name : Repository_E_TEMP_BACKUPS_ONLY
Physical_Location : My_Location

name : Repository_Internal_Backups
Physical_Location : My_Location

-> You get a powershell error querying location if unset. It should return empty string.

You cannot neither query IDs for a given location you can later translate.
Someting like "get-VBRItemsByLocationId -Id <location_ID>" that could list Name;ID;ObjectType fields.

I am trying to query such a way to retrieve cross-site links (ex vm located in LOC_A backuped to repository in LOC_B).

Thanks for your reply,
Have a nice week-end
Th
ThierryF
Expert
Posts: 129
Liked: 34 times
Joined: Mar 31, 2018 10:20 am
Contact:

Re: Querying VBR Object Location

Post by ThierryF »

Oleg,

Thanks for your reply. I just gave a check and same powershell error for unset location ...

get-vbrlocation : Failed to find location. Object Veeam.Backup.Core.CBackupRepository does not have any location assigned
At line:2 char:61
+ ... each ($obj in get-vbrbackuprepository) {get-vbrlocation -object $obj}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VBRLocation], Exception
+ FullyQualifiedErrorId : GetLocationErrorId,Veeam.Backup.PowerShell.Cmdlets.GetVBRLocation

Thanks !

Th
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Querying VBR Object Location

Post by oleg.feoktistov » 2 people like this post

Thierry,

I see your point now. I agree, it would make much more sense. And, by the way, thank you for cmdlet proposal! We will point it to a discussion.

Meanwhile, I've been scripting and found the workaround below using simple error handling:

Code: Select all

$ErrorActionPreference = 'Ignore'
    foreach ($obj in get-vbrbackuprepository) {
       $repLocation = get-vbrlocation -object $obj
       if (!$repLocation) {
        $repError = @{
            Component = $obj.Name
            Location = 'Not set'
            
           
       }
        $repError | select-object @{n='Component name';e={$_.Component}}, @{n='Location';e={$_.Location}}
       }
       else {
        $repLocation | select-object @{n='Component name';e={$obj.Name}}, @{n='Location';e={$_.Name}}
       }

}
It resulted in:

Code: Select all


Component name            Location
--------------            --------
Remote Repository Central Not set
Shared.Repository         Saint.P

All the best,
Oleg
ThierryF
Expert
Posts: 129
Liked: 34 times
Joined: Mar 31, 2018 10:20 am
Contact:

Re: Querying VBR Object Location

Post by ThierryF »

Thanks, I will give it a check ! Cool :-)

TH
ThierryF
Expert
Posts: 129
Liked: 34 times
Joined: Mar 31, 2018 10:20 am
Contact:

Re: Querying VBR Object Location

Post by ThierryF » 1 person likes this post

PS Error/Warning is gone when setting $ErrorActionPreference = 'silentlycontinue'.
Thanks for the tip !

Th
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Querying VBR Object Location

Post by oleg.feoktistov »

Both $ErrorActionPreference = 'SilentlyContinue' and $ErrorActionPreference = 'Ignore' should prevent the error from displaying.
The difference is 'SilentlyContinue' also appends an exception to the environmental variable $error, whereas 'Ignore' doesn't do that. :wink:

Glad to help!
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests