PowerShell script exchange
Post Reply
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

How do I list restore jobs?

Post by pshute »

I've like to get a list of running restore jobs, but Get-VBRJob doesn't list them. Is there another command to use?

Eg I'd like to be able to see Exchange item restores and guest file restores.
HannesK
Product Manager
Posts: 14844
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: How do I list restore jobs?

Post by HannesK » 1 person likes this post

Hello,
restore sessions (no real jobs) are covered by various get-*restoressession cmdlets

https://helpcenter.veeam.com/docs/backu ... l?ver=95u4
https://helpcenter.veeam.com/docs/backu ... l?ver=95u4

Get-VBRRestoreSession and Get-VBRExchangeItemRestoreSession might help you

Best regards,
Hannes
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: How do I list restore jobs?

Post by pshute »

Thanks for that. The data I want is in Get-VBRRestoreSession in the Options field. How do I extract the subfields in there? I need the InitiatorName. Apologies for my lack of Powershell knowledge.
HannesK
Product Manager
Posts: 14844
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: How do I list restore jobs?

Post by HannesK »

Apologies for my lack of Powershell knowledge.
same here - I do any scripting / programming by searching everything on the internet. So I can only guide you into a direction, but creating the real code would take me the same time like it takes for you :-)
teltrop
Novice
Posts: 7
Liked: never
Joined: Sep 04, 2019 1:56 pm
Contact:

Re: How do I list restore jobs?

Post by teltrop »

Dont know the exact property name but this should be what you are looking for:

Code: Select all

Get-VBRRestoreSession | Select-Object -Property InitiatorName


Another way would be:

Code: Select all

$RestoreSessions = Get-VBRRestoreSession
$RestoreSessions.InitiatorName
If you want to loop through each Session you might want to do it like this:

Code: Select all

$RestoreSessions = Get-VBRRestoreSession

foreach($RestoreSession in $RestoreSessions){
	$RestoreSession.InitiatorName
}
teltrop
Novice
Posts: 7
Liked: never
Joined: Sep 04, 2019 1:56 pm
Contact:

Re: How do I list restore jobs?

Post by teltrop »

Forgot to mention that if the information is inside for example options it needs to look like

Code: Select all

$RestoreSessions.Options.InitiatorName
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: How do I list restore jobs?

Post by pshute »

Doesn't work. I think the problem is that the contents of Options, which contains the InitiatorName, is xml.

This will list it for each job, but I don't know how to extract the InitiatorName:

Code: Select all

Get-VBRRestoreSession | select Options
I can get Options' methods with:

Code: Select all

Get-VBRRestoreSession | select Options |Get-Member
The only useful looking one is ToString(), but this gives an error:

Code: Select all

Get-VBRRestoreSession | select Options.ToString()
But it works this way (why?) and I can access and manipulate the xml as a string (used the substring method as an example), but surely there's a neater way:

Code: Select all

$RestoreSessions = Get-VBRRestoreSession
foreach($RestoreSession in $RestoreSessions){
	$RestoreSession.Options.ToString().substring(1,200)
}
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: How do I list restore jobs?

Post by veremin »

It's not clear what exact property you want to extract from restore session.

If you want to emulate the last script, then, the syntax used in the first two examples is incorrect, something like this might work better:

Code: Select all

(Get-VBRRestoreSession).Options.ToString()
Thanks!
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: How do I list restore jobs?

Post by jhoughes » 1 person likes this post

You can find this detail under the Info property (a few levels lower), rather than having to parse out the details from the string.

This will give you the job name, the creation time of the restore session, the reason entered in the session, and the user who initiated the session:

Code: Select all

Get-VBRRestoreSession | Select-Object -Property JobName, CreationTime, @{n='Reason';e={$_.Info.Reason}}, @{n='Initiator';e={$_.Info.Initiator.Name}}
You can also pull this detail from the 'RestoreSessionAudit' property.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: How do I list restore jobs?

Post by pshute »

Thanks, this is giving me what I want:

Code: Select all

Get-VBRRestoreSession | where {$_.IsWorking}| Select-Object -Property JobName, CreationTimeUTC, EndTimeUTC, IsCompleted, IsWorking, IsStarted, @{n='Initiator';e={$_.Info.Initiator.Name}}, @{n='Reason';e={$_.Info.Reason}}
It makes me realise how little I know about Powershell. I'm under the impression it's supposed to be self documenting, so I'm wondering how you knew:
- to use Select-Object instead of Select
- to use Info.Initiator.Name instead of InitiatorName that I could see in the Options field.
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: How do I list restore jobs?

Post by jhoughes »

Select is just the alias for Select-Object, so it's the same. I expanded it since you said you were new to PowerShell, so you can see what all is in use.

You need to use the Get-Member cmdlet to be able to inspect the properties of the object that you are getting returned.

If you need a GUI style tree view, check out the Show-Object cmdlet that us in the PowerShellCookbook module by Lee Holmes, it's in the PowerShell Gallery.

Using Get-Member is the closest to "self-documenting" since the .NET reflection will give you the object type, properties and methods.

Check out the Learn Learn PowerShell in a Month of Lunches to get some basics to help with these efforts, it'll walk you through these cmdlets and how to use them easily.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: How do I list restore jobs?

Post by pshute »

But how did you know the fields I wanted were also in the Info property? When I ran

Code: Select all

Get-VBRRestoreSession | select *
it didn't return anything that looked useful, but Options did.
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: How do I list restore jobs?

Post by jhoughes » 1 person likes this post

Honestly, some of it is knowing the PowerShell basics to objects, understand properties and definitions. Once you understand some of the basics, this becomes a lot easier.

Sometimes you have to just do some discovery to see what is contained within these objects returned by PowerShell, as these objects will vary across platforms, applications, or the code written by the author of any script/module.

Even I miss things in the results sometime, as I just found the Initiator property at the top level of the session object while writing this reply (Get-VBRRestoreSession | select Initiator)

For further explanation about how to perform some discovery, keep reading below.

Within Veeam objects, when you see object properties with a definition like 'Veeam.Backup.Model.CRestoreSessionInfo', that will be another object with additional properties contained within it.

You can determine these properties fairly easily with 2 different methods.

First, you can pipe your object to Get-Member and look at the Property members (I give a trimmed list just as an example):

Code: Select all

PS C:\Users\svc_veeam_br> $sessions = Get-VBRRestoreSession
PS C:\Users\svc_veeam_br> $sessions[0] | Get-Member -MemberType Property

   TypeName: Veeam.Backup.Core.CRestoreSession

Name                 MemberType Definition
----                 ---------- ----------
AuxData              Property   string AuxData {get;}
BaseProgress         Property   int BaseProgress {get;}
CreationTime         Property   datetime CreationTime {get;}
CreationTimeUTC      Property   datetime CreationTimeUTC {get;}
Description          Property   string Description {get;}
EndTime              Property   datetime EndTime {get;}
EndTimeUTC           Property   datetime EndTimeUTC {get;}
FileLogger           Property   Veeam.Backup.Core.IFileCommanderLogger FileLogger {get;}
Id                   Property   guid Id {get;}
Info                 Property   Veeam.Backup.Model.CRestoreSessionInfo Info {get;}
Initiator            Property   Veeam.Backup.Model.CBaseSessionInfo+SInitiator Initiator {get;}
...
Platform             Property   Veeam.Backup.Common.CPlatform Platform {get;}
RestoreSessionAudit  Property   Veeam.Backup.Core.RestoreSessionAudit RestoreSessionAudit {get;}
RestoreType          Property   Veeam.Backup.Model.CRestoreSessionInfo+ERestoreType RestoreType {get;}
Result               Property   Veeam.Backup.Model.CBaseSessionInfo+EResult Result {get;}
SessionInfo          Property   Veeam.Backup.Model.CBaseSessionInfo SessionInfo {get;}
State                Property   Veeam.Backup.Model.CBaseSessionInfo+EState State {get;}
StateXml             Property   string StateXml {get;}
Tracer               Property   Veeam.Backup.Core.ILogTracer Tracer {get;}
Uid                  Property   Veeam.Backup.Model.CRestoreSessionUid Uid {get;}
The second way to find these properties is just to look within the results that you get back from piping the session to either 'select *' or 'fl *'.

Either of those cmdlets will display all properties of the input object since you declared '*' to the Properties parameter (just trust that if you don't immediately get it before reading up on it). The full property list will give you some properties with really long names as their value/definition, so you can try using them as the property within Select-Object.

(Trimmed results a bit here also)

Code: Select all

PS C:\Users\svc_veeam_br> $sessions = Get-VBRRestoreSession
PS C:\Users\svc_veeam_br> $sessions[0] | fl *

Info                 : Veeam.Backup.Model.CRestoreSessionInfo
Uid                  : 611ae54f321e410eb29a0008545f9ebc
LeaseUid             : d831004f0d3647d0b72c82392c16d00d
Initiator            : Veeam.Backup.Model.CBaseSessionInfo+SInitiator
OibId                : 5b7739bb-89fb-4b2b-a121-3d73a0f51271
Platform             : EVmware
Options              : <FlrInfo BackupName="AUSVCENTER-NoTag" OibDT="09/16/2019 04:49:51" MountId="00000000-0000-0000-0000-000000000000"><Data OibId="5b7739bb-89fb-4b2b-a121-3d73a0f51271" IsVbrSvcRestoreOwner="True" InitiatorName="FSGLAB\jhoughes"
                       InitiatorSid="S-1-5-21-1579299889-1624571845-370692084-1104" ShareCredsId="00000000-0000-0000-0000-000000000000" EsxId="00000000-0000-0000-0000-000000000000" PoolRef="" FolderRef="" IsWinFlrFromSanSnapshot="False" Reason="File restore re
                       CreatorType="1" IsEnterpriseRestore="False" CloudConnHostId="00000000-0000-0000-0000-000000000000" CloudProviderId="00000000-0000-0000-0000-000000000000" GuestCredsId="00000000-0000-0000-0000-000000000000" IsGuiFlrRequest="False" Comlpet
                       CancelExistingRestoreTask="False" AppliencePlatform="0" UseHostApiForOriginalVm="False" OverwriteItems="False"><RestoreItem Name="XAMLGuiSnippetWBetterErrorHandling.ps1" Path="D:\Code\XAMLGuiSnippetWBetterErrorHandling.ps1" Size="0" Type
...
RestoreSessionAudit  : Veeam.Backup.Core.RestoreSessionAudit
...
JobType              : FileLevelRestore
JobName              : FLR_[ausdev01]
Name                 : FLR_[ausdev01]
...
IsCompleted          : True
IsWorking            : False
IsStarting           : False
IsPostprocessing     : False
JobId                : 43f215ba-ed0b-4809-8cd8-22071d0da188
Result               : Success
State                : Stopped
EndTime              : 9/16/2019 11:15:52 AM
EndTimeUTC           : 9/16/2019 11:15:52 AM
CreationTime         : 9/16/2019 11:15:00 AM
...
Tracer               : Veeam.Backup.Core.CSessionLogTracer
I hope that some of this helps until you get the basics of manipulating objects in PowerShell.

I'd also suggest again the Show-Object cmdlet, since that will easily show you which objects have additional information, as you can see graphically that they can be expanded.

It wasn't until trimming the results and capturing this screenshot that I caught the Initiator property at the top level, so sometimes we all have to look, or even look again to be sure. :D

Image
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests