PowerShell script exchange
Post Reply
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

get backup size for Windows Agent with Powershell

Post by Danh3 »

Hello team

I'm trying to pull up backup size for Windows Agent servers with Powershell for last 4 weeks, and show ZERO byte for size of app, read and transferred

Output:

Code: Select all

Name        : XXXXX
Status      : Success
StartTime   : 10/2/2022 3:00:14 AM
EndTime     : 10/2/2022 3:00:15 AM
Size        : 0
Read        : 0
Transferred : 0
Duration    : 00:00:01
Script:

Code: Select all

$jobs = Get-VBRComputerBackupJob | where {$_.name -eq "XXXXXX"}
$taskSessions = @()
$g5 = Get-VBRComputerBackupJobSession
$sessions = $g5 | where {($_.JobId -eq $jobs.id) -and( ($_.CreationTime -ge [datetime]::parseexact($convertday, 'dd-MMM-yy', $null) -and $_.CreationTime -le [datetime]::parseexact($convertday2, 'dd-MMM-yy', $null)))} 
           
foreach ($session in $sessions) {
               $tasks = Get-VBRTaskSession -Session $session
               $taskSessions += $tasks
               }
$taskSessions | select Name, Status, @{n='StartTime';e={$_.Info.Progress.StartTimeUtc}}, `
            @{n='EndTime';e={$_.Info.Progress.StopTimeUtc}}, @{n='Size';e={$_.Info.Progress.TotalSize}}, `
            @{n='Read';e={$_.Info.Progress.ReadSize}}, `
            @{n='Transferred';e={$_.Info.Progress.TransferedSize}}, @{n='Duration';e={$_.Info.Progress.Duration.ToString()}}
             
                
        }

Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

Re: get backup size for Windows Agent with Powershell

Post by Danh3 »

Found the resolution from the below thread and to make it work, append '?*' to the jobname (e.g "Backup_Job_ XXXX?*") though not sure why this way works ?

https://community.veeam.com/discussion- ... ackup-2598

**** output ***

Name : XXXX
Status : Success
StartTime : 10/1/2022 9:00:16 AM
EndTime : 10/1/2022 9:05:57 AM
Size : 121.16
Read : 1.95
Transferred : 0.63
Duration : 00:05:41


**** new script works for me***

$taskSessions = @()
$g5 = Get-VBRComputerBackupJobSession -name "Backup_Job_ XXXX?*"
$sessions = $g5 | where {( ($_.CreationTime -ge [datetime]::parseexact($convertday, 'dd-MMM-yy', $null) -and $_.CreationTime -le [datetime]::parseexact($convertday2, 'dd-MMM-yy', $null)))}

foreach ($session in $sessions) {
$tasks = Get-VBRTaskSession -Session $session
$taskSessions += $tasks
#$taskSessions

}


$taskSessions | select Name, Status, @{n='StartTime';e={$_.Info.Progress.StartTimeUtc}}, `
@{n='EndTime';e={$_.Info.Progress.StopTimeUtc}}, @{n='Size';e={ [math]::Round(($_.Progress.TotalSize/1GB),2)}}, `
@{n='Read';e={[math]::Round(($_.Progress.ReadSize/1GB),2)}}, `
@{n='Transferred';e={[math]::Round(($_.Progress.TransferedSize/1GB),2)}}, @{n='Duration';e={$_.Progress.Duration.ToString()}}


}
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: get backup size for Windows Agent with Powershell

Post by david.domask » 1 person likes this post

Hi!

Glad you found a solution :)

The answer as to why adding ?* helps is that these are wildcard characters; the Get-VBRComputerJobSession cmdlet runs code that calls a stored procedure in the Veeam Configuration Database GetJobSessionsByType and checks the job_name field.

The post you found actually has it a little wrong; ? is for any single character _in that position_ and * is any characters: https://learn.microsoft.com/en-us/power ... rshell-7.3

In the DB, the job_names are stored for agent sessions as

[jobname] - [host being backed up in job]

So their regex is a little off; they could just use * and it will match all of the sessions, but it might pull the Policy Sessions also instead of just the backup sessions.

More likely you want to do

Get-VBRComputerJobSession -Name "$($NameVariable) - *"

But it's up to you and what you're trying to pull I suppose :)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests