PowerShell script exchange
Post Reply
aheath
Influencer
Posts: 13
Liked: never
Joined: May 09, 2019 1:56 pm
Full Name: Ashley Heath
Contact:

Newbie question

Post by aheath »

I have seen a few post using statements like the example below
Get-VBRRestorePoint -Name "server1" | where {($_.GetBackup().JobType -eq "VmTapeBackup")
I'm a relative newbie to powershell, but know I can get the methods and properties of Get-VBRRestorePoint using Get-Member, so I can see that Get-VBRRestorePoint has a method called GetBackup, but how can I see what the GetBackup method does or what it can return in addition to VmTapeBackup shown in the example? And what is it called the .VmTapeBackup part technically called, an explanation in simple terms please or link to documentation appreciated
Thanks in advance
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Newbie question

Post by oleg.feoktistov »

Hi Ashley,

Simply put, since Powershell is built on .NET Framework, it uses .NET notations and style everywhere.
To see what the method you want to explore returns you would look at Definition property when calling Get-Member on anything.
Say, calling it on Get-VBRRestorePoint and then filtering it out by the method name would show us the following definition:

Code: Select all

 PS C:\Program Files> Get-VBRRestorePoint | get-member | where {$_.Name -eq 'GetBackup'}


   TypeName: Veeam.Backup.Core.COib

Name      MemberType Definition                           
----      ---------- ----------                           
GetBackup Method     Veeam.Backup.Core.CBackup GetBackup()
Where Veeam.Backup.Core.CBackup is a return type (or class) and GetBackup() is a method name.
So, we have a method called GetBackup(), which returns object of CBackup type (Veeam.Backup.Core is just a location for CBackup type. Such location is called namespace). Usually, as in this example, the action is described in the method's name. To check what we have in an object of CBackup type you could call GetBackup() method on a single restore point, as in the following example:

Code: Select all

$rp = Get-VBRRestorePoint | select -Last 1
$rp.GetBackup() 
Or just call Get-VBRBackup.

There is, of course, a more advanced way to access properties and methods of a class without calling cmdlets. I can also share it if you want.

Now, about "VmTapeBackup". If you are asking what is a predefined value, which is stored in a particular property, called, it is an enum value. You can read more about enums in powershell here. If you were asking about something else, please elaborate.


Hope my explanation helps,
Oleg
ratkinsonuk
Expert
Posts: 111
Liked: 16 times
Joined: Dec 10, 2018 10:59 am
Full Name: Robert Atkinson
Contact:

Re: Newbie question

Post by ratkinsonuk »

Having gone through a similar trial by fire Ashley, once you know the class definition, you can use these methods to help expose the class...

[Veeam.Backup.Core.CBackup].DeclaredMethods | format-list
[Veeam.Backup.Core.CBackup].DeclaredProperties | format-list

I haven't seen a way of exposing the method descriptions yet (assuming they're present in the source), so it's a case of best guess followed by trial and error....unless Oleg knows how to get to them?
aheath
Influencer
Posts: 13
Liked: never
Joined: May 09, 2019 1:56 pm
Full Name: Ashley Heath
Contact:

Re: Newbie question

Post by aheath »

Thankyou so much Oleg and Robert for taking the time to reply with such detail, that really does help so much, as a non programmer some of these concepts are at bit over my head, but learning more and more all the time
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Newbie question

Post by oleg.feoktistov »

@ratkinsonuk, what do you mean by method description? If it is what a method does precisely, it's either described in source code comments or implied in method's name and implementation logic. I'm not sure there is a way to dump method description other than that, especially through Powershell.
ratkinsonuk
Expert
Posts: 111
Liked: 16 times
Joined: Dec 10, 2018 10:59 am
Full Name: Robert Atkinson
Contact:

Re: Newbie question

Post by ratkinsonuk »

Morning Oleg. I was talking about this sort of annotation, that can be picked up by IDE's...

Code: Select all

<#
    .SYNOPSIS
        Adds in help comments
 
    .DESCRIPTION
        Highlight the parameters of a function and hit Alt+F6 to add in help comments
        Based off the Add-Help function in the PowershellISEModule by Ed Wilson
        https://www.powershellgallery.com/packages/PowerShellISEModule/
 
    .NOTES
        AUTHOR: Ryan Ephgrave
        LASTEDIT: 09/28/2015 14:51:13
 
   .LINK
        http://ephingadmin.com
#>
I don't even know what support PowerShell gives for this kind of functionality, but I'm pretty certain I've seen it in some places.
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Newbie question

Post by soncscy »

For all, most of the stuff with the internal methods for Veeam objects should probably be avoided unless absolutely necessary (i.e., the native cmdlets don't offer it).

aheath, forgive me if I make a bold assumption, but I'm guessing you found this line somewhere, right? Basically someone likely wrote this to be clever and put as much into one Powershell line as they could.


The same could be done if they were to do:

Code: Select all

$TapeBackups = Get-VBRTapeBackup  #Note: cmdlet is obsolete
$Restorepoints = Get-VBRRestorepoint -Backup $TapeBackups
Now, likely per the note, the reason they used GetBackups() was just to try to condense the line/maybe avoid the obsolete cmdlet, but this is a native method to the object, and as such, not really intended for public use. The .NET methods will change from release to release, and especially when you're just starting out, it's best to stick with the official information returned by the official endpoints (the cmdlets you see in the cmdlet User Guide), else you might build into a scenario where the method you rely on no longer works as described and now you're stuck :(

Getting information on the methods is kind of tricky; within Powershell, you're just going to see the arguments that the method expects, but it likely is not going to be so clear on what some of the arguments mean or how to properly make them because this isn't meant to be exposed to Powershell really; it can be for sure, but you're playing with .NET calls here directly to the code.

What ratkinsonuk is looking for usually isn't how it's presented for the .NET calls, and you need to either just suss out what the method wants based on the name and the arguments that Powershell shows, or use a Decompiler and check the relevant class from the Veeam modules and look at exactly what the methods are asking for, which for right now I suggest avoid :) It's less about it being "complex" and more that again, you put yourself in a situation that is not supported as these methods can and will change from release to release and you'll have a lot of headaches to maintain.

They're good question you have and certainly ones I had when I started to learn how Powershell works, and ultimately it's a lot easier to see what you can fuss about with using the native cmdlets instead of touching the .NET elements. I suppose this might be where Powershell gets its "verbose" reputation from, but it's for a good reason in my opinion.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Newbie question

Post by oleg.feoktistov »

What Harvey said. Since VBR .NET methods are not intended for public use, we don't describe what they do in cmdlet help notations, which you encountered, Robert. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests