PowerShell script exchange
Post Reply
masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Veeam Agent in protection group, find sessions

Post by masonit » Nov 05, 2019 8:43 am

Hi

Is there any support for finding sessions for Veeam Agent in protection group? Get-VBRBackupSession does not work.

\Masonit

jhoughes
Veeam Software
Posts: 114
Liked: 28 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Veeam Agent in protection group, find sessions

Post by jhoughes » Nov 05, 2019 12:47 pm 2 people like this post

Here's some code that will return all job & task sessions for agent backup jobs. You can add a parameter to specify a job name, if you need to target a single job.

As written, it will return these as the variables $AllJobSessions (job session IDs only), and $AllTaskSessions (full details of each task session).

Here's the code to query the agent job task sessions, hope it helps.

Code: Select all

$AgentJobs = Get-VBRJob | Where-Object {$_.JobType -eq 'EpAgentBackup'}

[System.Collections.ArrayList]$AllJobSessions = @()
[System.Collections.ArrayList]$AllTaskSessions = @()
foreach ($AgentJob in $AgentJobs){

    $JobSessions = [Veeam.Backup.Core.CBackupSession]::GetByJob($AgentJob.Id)

    if ([bool]$JobSessions){

        foreach ($CurrentSession in $JobSessions) {
            
          $auxdata = [xml]$CurrentSession.Info.AuxData
          $SessionIDs = (($auxdata.AuxData.EpPolicyJobSessionContext.Sessions) -split ';')

          foreach ($SingleSessionID in $SessionIDs) {
            if (![String]::IsNullOrWhiteSpace($SingleSessionID)) {

              $null = $AllJobSessions.Add($SingleSessionID)
  
            }
  
          }

        }

      }

    $UniqueJobSessions = $AllJobSessions | Select-Object -Unique
    
    foreach ($CurrentSessionID in $UniqueJobSessions) {

      $TaskSessions = Get-VBRTaskSession (Get-VBRSession -Id $CurrentSessionID)

      foreach ($CurrentTaskSession in $TaskSessions) {

        $null = $AllTaskSessions.Add($CurrentTaskSession)

      }

    }

}

Write-Output $AllTaskSessions
Only the $AllTaskSessions will be written to the pipeline, and you can dig further into the details with:

Code: Select all

$AllTaskSessions | Select-Object -First 1 -Property *
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit » Nov 06, 2019 8:13 am

Thanks!

I guess cmdlets for this will be available in later versions?

\Masonit

veremin
Product Manager
Posts: 17017
Liked: 1462 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Agent in protection group, find sessions

Post by veremin » Nov 06, 2019 1:45 pm

Correct, we're planning to have a specific cmdlet in version 10. Thanks!

masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit » Nov 08, 2019 1:59 pm

Great!

I am trying to see if I can get disk usage (not total size) on Veeam Agents (protection group) from VBR server. I can see in the session info for each agent that VBR is collecting this info, ex:

2019-11-08 01:00:16 :: Total size: 1004,6 GB (590,6 GB used)

Is there a better way of collecting this info than with session logs?

\Masonit

masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit » Nov 11, 2019 3:07 pm

jhoughes wrote:
Nov 05, 2019 12:47 pm
Here's some code that will return all job & task sessions for agent backup jobs. You can add a parameter to specify a job name, if you need to target a single job.

As written, it will return these as the variables $AllJobSessions (job session IDs only), and $AllTaskSessions (full details of each task session).

Here's the code to query the agent job task sessions, hope it helps.

Only the $AllTaskSessions will be written to the pipeline, and you can dig further into the details with:

Hi jhoughes

Is it possible to control tasksessions to collect? Maybe just sessions for last 4 days? It seems like it collects all available sessions. Takes a long time..

\Masonit

jhoughes
Veeam Software
Posts: 114
Liked: 28 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Veeam Agent in protection group, find sessions

Post by jhoughes » Nov 11, 2019 3:15 pm

Sure, at the top of the 'foreach ($CurrentSession in $JobSessions)' loop, you could add an if statement to check if the date is within the last 4 days.

It would skip the job sessions otherwise.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit » Nov 12, 2019 9:38 am

Thanks!

Any idea how to collect disk usage on Veeam Agents from VBR?

\Masonit

veremin
Product Manager
Posts: 17017
Liked: 1462 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Agent in protection group, find sessions

Post by veremin » Nov 12, 2019 5:04 pm 1 person likes this post

Session should have a backedupsize property that seems to provide information you're after. Thanks!

masonit
Service Provider
Posts: 234
Liked: 16 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Magnus
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit » Nov 13, 2019 4:07 pm

Yes! Thanks! :)

\Masonit

Post Reply

Who is online

Users browsing this forum: Egor Yakovlev and 3 guests