PowerShell script exchange
Post Reply
hari
Influencer
Posts: 13
Liked: 2 times
Joined: Apr 29, 2021 9:36 am
Full Name: harikrishnai
Contact:

Filter Sessions by Date

Post by hari »

Is it possible to filter job sessions by date rather than getting all jobs sessions.
Currently I am getting job sessions by,

# for vm jobs

Code: Select all

$allsessions = Get-VBRBackupSession  | ? { $_.jobtype -ieq "Backup" }
# for agent jobs, where $AgentJob is a agent job

Code: Select all

$JobSessions = [veeam.backup.core.cbackupsession]::GetByJob($AgentJob.Id)
# for tape jobs, where $TapeJob is a tape job

Code: Select all

$Sessions = [veeam.backup.core.cbackupsession]::GetByJob($TapeJob.id)
# for sure backup sessions

Code: Select all

$allsessions = Get-VSBSession
And I found these online and where does is it documented about these type of commands
[veeam.backup.core.cbackupsession]::GetByJob()
I am referring to https://helpcenter.veeam.com/docs/backu ... ml?ver=110 for any command.
I am new to this scripting so enlighten me how to do this.
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Filter Sessions by Date

Post by david.domask » 1 person likes this post

Hey Hari,

I'd advise against using the internal methods as you never know when they will change in future releases.

All of the job types have nominal Get-VBR[something]Sessions.

Get-VBRBackupSession == Most Backup sessions
Get-VBRComputerBackupJobSession == Agent backup sessions created in Veeam console
Get-VBRSession == Pass a Tape Job object to -Job parameter to get the Job Sessions.

To sort by creation time, you would then do something like:

Code: Select all

PS C:\Users\Administrator> $Sessions = Get-VBRComputerBackupJobSession
PS C:\Users\Administrator> $Sessions | sort -Property CreationTime -Descending | select JobId, CreationTime | select -First 5

JobId                                CreationTime
-----                                ------------
6960378f-b069-4b09-a078-d18b2a283ff6 1/14/2022 14:15:18
28fbf96a-ffcf-4006-bcd3-40d392fce589 1/14/2022 14:14:27
6960378f-b069-4b09-a078-d18b2a283ff6 1/14/2022 14:10:42
28fbf96a-ffcf-4006-bcd3-40d392fce589 1/14/2022 14:10:27
6960378f-b069-4b09-a078-d18b2a283ff6 1/14/2022 14:06:06
(Note: The last two selects I added just for readbility sake -- there's no need for them or you can customize what properties you want to show in your output)
And I found these online and where does is it documented about these type of commands
These are dotNet methods that you're calling via Powershell Reflection. These are not supported and not documented as a result. Even minor patches typically change method names, so it's always a gamble that your script might stop working when using these on updates. It's best to stay to the supported endpoints listed in this user guide article: https://helpcenter.veeam.com/docs/backu ... ml?ver=110
David Domask | Product Management: Principal Analyst
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Filter Sessions by Date

Post by chris.arceneaux » 1 person likes this post

Hi Hari,

Thanks for the detailed request! David covered how to use our official PowerShell cmdlets. Using them, you'll pull the sessions and then you'll filter them by date using built-in PowerShell methods like the Where-Object cmdlet. As David mentioned, this is the recommended method.

I have also identified an undocumented API call to do what you want. Use at your own risk and know that this call is subject to change without warning in a future release:

Code: Select all

[veeam.backup.core.cbackupsession]::GetByTypeAndTimeInterval(String jobType,DateTime fromTime,DateTime toTime)
Here's an example using the call:

Image

Code: Select all

$start = (Get-Date).AddDays(-1)
$end = Get-Date
[veeam.backup.core.cbackupsession]::GetByTypeAndTimeInterval("backup",$start,$end)
[veeam.backup.core.cbackupsession]::GetByTypeAndTimeInterval("EpAgentBackup",$start,$end)
[veeam.backup.core.cbackupsession]::GetByTypeAndTimeInterval("EpAgentPolicy",$start,$end)
hari
Influencer
Posts: 13
Liked: 2 times
Joined: Apr 29, 2021 9:36 am
Full Name: harikrishnai
Contact:

Re: Filter Sessions by Date

Post by hari »

Thank you david and chris. So Veeam cmdlets do not filter job sessions so need to use Where-Object cmdlet
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests