PowerShell script exchange
Post Reply
stressederic
Novice
Posts: 4
Liked: never
Joined: Jun 29, 2020 12:04 pm
Full Name: gareth roberts
Contact:

Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by stressederic »

I'm trying to obtain the repository path of backup jobs and have found the value under the DirPath property of the FindLastBackup() method however although I can view the value via select-object if I try to query the value directly or use the "-expandproperty" option "IsVbm" is returned instead of the value

#Returns the expected value

Code: Select all

$jobs = Get-VBRJob -Name "JOB12345"
$jobs.FindLastBackup() | select-object DirPath

DirPath
-------
D:\JOB12345
#Returns IsVbm

Code: Select all

$jobs.FindLastBackup().DirPath

IsVbm
-----
False
or

Code: Select all

$jobs.FindLastBackup() | select-object -ExpandProperty DirPath

IsVbm
-----
False
This problem does not occur for other properties of FindLastBackup() such as jobsourcetype. I am querying a Veeam Backup and Replication server version 10.0.0.4461 P1

A similar forum post powershell-f26/get-job-backup-target-di ... 40318.html was raised a few years ago but no resolution was posted just a workaround.
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by jhoughes »

Just use this:

Code: Select all

$jobs.FindLastBackup().DirPath.ToString()
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
stressederic
Novice
Posts: 4
Liked: never
Joined: Jun 29, 2020 12:04 pm
Full Name: gareth roberts
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by stressederic »

Thanks Joe that solution works well.

Don't suppose you can explain why the value can't be outputted directly, academic at this point just bugs me not knowing why.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by oleg.feoktistov » 1 person likes this post

An object you receive to the output when you call $jobs.FindLastBackup() is of CBackup type. Inside this type a method to directly get DirPath is implemented:

Code: Select all

PS C:\WINDOWS\system32> job = Get-VBRJob
$backup = $job.FindLastBackup()
$backup.GetType()
$backup | Select-Object DirPath
$cbackup = [Veeam.Backup.Core.CBackup]
$cbackup.DeclaredProperties | where {$_.Name -eq 'DirPath'} 
 
 IsPublic IsSerial Name                                     BaseType                                       
-------- -------- ----                                     --------                                       
True     False    CBackup                                  System.Object  

DirPath : BACKUP-TO-SOBR

MemberType       : Property
Name             : DirPath
DeclaringType    : Veeam.Backup.Core.CBackup
ReflectedType    : Veeam.Backup.Core.CBackup
MetadataToken    : 385891610
Module           : Veeam.Backup.Core.dll
PropertyType     : Veeam.Backup.Common.CLegacyPath
Attributes       : None
CanRead          : True
CanWrite         : False
GetMethod        : Veeam.Backup.Common.CLegacyPath get_DirPath()
SetMethod        : 
IsSpecialName    : False
CustomAttributes : {}
So, despite the fact that DirPath property inside CBackup type actually holds an object of CLegacyPath type, when returning $jobs.FindLastBackup() you see a precise name of the path.

Now, if we dive inside CLegacyPath type, we can see that the field for getting a DirPath name is implemented internally, while there is only isVbm property that is publicly available:

Code: Select all

PS C:\WINDOWS\system32> $path = [Veeam.Backup.Common.CLegacyPath]
$path.DeclaredFields | select  Name, FieldType, ReflectedType -First 1 | fl

Name          : _internal
FieldType     : System.String
ReflectedType : Veeam.Backup.Common.CLegacyPath

PS C:\WINDOWS\system32> $path.DeclaredProperties | select Name, PropertyType, ReflectedType | fl
Name          : Empty
PropertyType  : Veeam.Backup.Common.CLegacyPath
ReflectedType : Veeam.Backup.Common.CLegacyPath

Name          : IsVbm
PropertyType  : System.Boolean
ReflectedType : Veeam.Backup.Common.CLegacyPath

Name          : InternalComparer
PropertyType  : System.Collections.Generic.IEqualityComparer`1[Veeam.Backup.Common.CLegacyPath]
ReflectedType : Veeam.Backup.Common.CLegacyPath 

That's why you see an actual repository path name in CBackup object and still need to apply ToString() method when acting on CLegacyPath object.
Thanks!
stressederic
Novice
Posts: 4
Liked: never
Joined: Jun 29, 2020 12:04 pm
Full Name: gareth roberts
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by stressederic »

Thanks, Oleg. Appreciate the detailed explanation
aidybarker
Lurker
Posts: 2
Liked: 1 time
Joined: Dec 24, 2014 9:15 am
Full Name: Adrian Barker
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by aidybarker »

Thank you. Same issue here with FilePath. Could only get as far as boolean IsVbm - still not 100% clear on why I need to use ToString(), even after that great explanation, but I'll take your word for it - it works!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get-VBRJob not returning the DirPath property in the FindLastBackup method

Post by oleg.feoktistov »

Sorry, @aidybarker, I don't have precise info on WHY it was implemented like that initially. In terms of Veeam code, CLegacyPath type is ancient as it belongs to core classes. My guess is that class contained info to some point essential for internal tests, but to make it easier for others to read and consume, it all led to .ToString() method included. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests