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 Software
Posts: 190
Liked: 61 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
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 Extraordinaire | @AustinVMUG & @ATXPowerShell leader | VMUG US South Regional Champion | VMware vExpert | 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: 415
Liked: 132 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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest