PowerShell script exchange
Post Reply
stephan.troxler
Influencer
Posts: 17
Liked: 1 time
Joined: Jul 16, 2024 9:30 am
Full Name: Stephan
Contact:

Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by stephan.troxler »

I've just noticed a strange behaviour in objects returned by get-vbrbackup. It seems that the "Dirpath" property returns something different when accessed via get and not converted to a string. Is this a bug or is there an explanation for this? Are there other properties that behave like this?

Code: Select all

$test = get-vbrbackup -id <ID>

PS C:\> $test.Dirpath
IsVbm
-----
False

PS C:\> $test | select Dirpath

DirPath
-------
Backup-Standalone-Daily

PS C:\> $test.Dirpath.ToString()
Backup-Standalone-Daily
david.domask
Veeam Software
Posts: 2629
Liked: 611 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by david.domask »

Hi Stephan,

Yes, it's expected behavior; I forget the specifics on this, but in short DirPath itself is _not_ a string value, it's a CLegacyPath object:

Code: Select all

PS C:\Users\david.LAB> $backup.DirPath|gm


   TypeName: Veeam.Backup.Common.CLegacyPath

Name                    MemberType Definition
----                    ---------- ----------
AddDelimiterIfNeeded    Method     Veeam.Backup.Common.CLegacyPath AddDelimiterIfNeeded(string delimiter)
CompareTo               Method     int CompareTo(Veeam.Backup.Common.CLegacyPath other), int IComparable[CLegacyPath...
Equals                  Method     bool Equals(Veeam.Backup.Common.CLegacyPath other), bool Equals(System.Object obj...
FilterInvalidCharacters Method     Veeam.Backup.Common.CLegacyPath FilterInvalidCharacters(Veeam.Backup.Common.EPath...
GetHashCode             Method     int GetHashCode()
GetObjectData           Method     void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Ru...
GetSchema               Method     System.Xml.Schema.XmlSchema GetSchema(), System.Xml.Schema.XmlSchema IXmlSerializ...
GetType                 Method     type GetType()
ReadXml                 Method     void ReadXml(System.Xml.XmlReader reader), void IXmlSerializable.ReadXml(System.X...
ToString                Method     string ToString(), string ToString(System.IFormatProvider formatProvider)
Trim                    Method     Veeam.Backup.Common.CLegacyPath Trim()
TrimDelimiter           Method     Veeam.Backup.Common.CLegacyPath TrimDelimiter(char delimiter)
WriteXml                Method     void WriteXml(System.Xml.XmlWriter writer), void IXmlSerializable.WriteXml(System...
IsVbm                   Property   bool IsVbm {get;}


PS C:\Users\david.LAB> $backup.DirPath.ToString()
E:\Repo1\dd-malware-box-backup
As you can see, it's not just a string object, this is special object returned, and when you call ToString() and call the property by passing it to Select-Object, there is some work being done outside of the object to return the path you see.

In short, just call it with $backup.DirPath.ToString() to get the VBM folder path, which will reflect the job folder name you'd see on the repository.
David Domask | Product Management: Principal Analyst
EWMarco
Service Provider
Posts: 48
Liked: 7 times
Joined: Feb 20, 2023 9:28 am
Full Name: Marco Glavas
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by EWMarco »

Is there a way to recognize that this is the way you have to handle the object without just knowing?
david.domask
Veeam Software
Posts: 2629
Liked: 611 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by david.domask »

Hi Marco,

Regrettably DirPath is just a "weird one" -- I don't remember any other properties where it's not as immediately clear, but in fact, I would advise that any time you see what you think is a string not acting like a string, run the GetType() method or pipe it to Get-Member and check the type -- likely it's not a string.

I think DirPath is the only one I can recall that has this nuance, so in otherwords, I wouldn't expect you have to think about such things for other properties, as they will either be normal properties instead of objects, or it will be clear it's an object that you need to delve deeper into.
David Domask | Product Management: Principal Analyst
stephan.troxler
Influencer
Posts: 17
Liked: 1 time
Joined: Jul 16, 2024 9:30 am
Full Name: Stephan
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by stephan.troxler »

Hi David, thank you for the clarification!
I've found some more properties with this behaviour meanwhile, they all return something useful when converted to a string. Those properties seem to have in common returning "IsVbm" when accessed normal.
david.domask
Veeam Software
Posts: 2629
Liked: 611 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by david.domask »

Hi Stephan,

Are they CLegacyPath type objects by chance?
David Domask | Product Management: Principal Analyst
stephan.troxler
Influencer
Posts: 17
Liked: 1 time
Joined: Jul 16, 2024 9:30 am
Full Name: Stephan
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by stephan.troxler »

Unfortunately I don't have an example ready, I was just playing around with some objects. I will verify this when I find the next one.
david.domask
Veeam Software
Posts: 2629
Liked: 611 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Strange behaviour of "get-vbrbackup" items when Property is not converted to string

Post by david.domask »

No worries, just I figure it's probably the same or something similar that pulls from a similar behavior. To be honest, I would suggest it's pretty safe to say if it has property IsVBM, just use ToString() for now to get the data out of it, I don't think it's worth going over every property that might be affected :) But in general as we're working on improving the Powershell endpoints, many of these nuances are being resolved and the new cmdlets have normal properties that don't need special consideration. Our last few releases have cleaned up a lot of the powershell semantics and likely little nuances like this will be handled also.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests