PowerShell script exchange
Post Reply
cornel.florea
Lurker
Posts: 1
Liked: never
Joined: Feb 11, 2021 6:18 am
Full Name: Corne Florea
Contact:

Get last result for Windows Agent job and Tape job

Post by cornel.florea »

Hello ,

I am trying to build a failure report for all types of sessions. I manage do get the results with Get-VBRBackupSession

but the Tape jobs and Windows agent jobs are not included. I tried Get-VBRComputerBackupJobSession but it doesn't filter anything.

any other way to get Tape and Agent jobs?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by oleg.feoktistov »

Hi and welcome to the R&D Forums!

For agent backup job sessions use Get-VBRComputerBackupJobSession. As for tape job sessions - we have Get-VBRSession, but we are planning to enhance tape sessions support in future releases since this cmdlet is pretty old and takes info from table with general info anyways. It also does require -Job parameter, so you'll need to loop over tape jobs array:

Code: Select all

$tapeJobs = Get-VBRTapeJob
foreach ($tapeJob in $tapeJobs) {
  Get-VBRSession -Job $tapeJob
}
Thanks,
Oleg
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by oleg.feoktistov »

Forgot to mention that we are aware of filtering issues with Get-VBRComputerBackupJobSession cmdlet and already created bug for that.
You might try using the code below though for getting the last agent backup job session:

Code: Select all

$session = Get-VBRComputerBackupJobSession | Sort-Object -Descending -Property CreationTime
$session[0] 
Thanks!
Joelex1
Lurker
Posts: 1
Liked: never
Joined: Oct 25, 2021 4:18 am
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by Joelex1 »

Hello

I have the below script that provides the list of backup jobs that ran over the last 24 hours which includes client names - it work for VM's but not agent backups.

Not getting far with Get-VBRComputerBackupJobSession. Is there a way to get similar output for agent backups?

Code: Select all

#get jobs which run for last 24 hours
$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-24)}
 
#get each client from the job 
$clients = @()
foreach ($session in $vbrsessions) {
$clients += $session.gettasksessions()| Select Jobname, Name, Status,@{n='StartTimeLocal';e={$_.Progress.StartTimeLocal}}, @{n='EndTimeLocal';e={$_.Progress.StopTimeLocal}} }
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by oleg.feoktistov »

Yes, GetTaskSessions() method doesn't exist in an entity you get with Get-VBRComputerBackupJobSession.
Have you tried using official Get-VBRTaskSession cmdlet instead?

Code: Select all

$sessions = Get-VBRComputerBackupJobSession
foreach ($session in $sessions) {
  Get-VBRTaskSession -Session $session
}
Thanks!
ian6754
Novice
Posts: 4
Liked: never
Joined: Oct 29, 2021 2:09 pm
Full Name: Ian Midgley
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by ian6754 »

Hi, I've been trying to work through this and while the snip posted does work, the equivalent one liner doesn't.

Code: Select all

Get-VBRComputerBackupJobSession | % { Get-VBRTaskSession -Session $_ }
Any idea why this doesn't work? It does work if the Get-VBRComputerBackupJobSession command in enclosed by parentheses if that casts any light on the issue. I'm not a Powershell guru but I'm guessing the parentheses are coercing the return type somehow the same as assigning it to a variable does. Is this a bug?

Code: Select all

(Get-VBRComputerBackupJobSession) | % { Get-VBRTaskSession -Session $_ }
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by david.domask »

Hi @ian6754

It's because of how the pipeline handles the passing of the output of the two commands. The first returns a List and the later returns individual objects, and powershell can't transform the List to a VBRSession Object:

Code: Select all

PS C:\Users\Administrator> Get-VBRComputerBackupJobSession | Foreach{$_.GetType()}

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     List`1                                   System.Object


PS C:\Users\Administrator> ^C
PS C:\Users\Administrator> (Get-VBRComputerBackupJobSession) | Foreach{$_.GetType()}

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VBRSession                               Veeam.Backup.PowerShell.Infos.VBRUniqueObject
True     False    VBRSession                               Veeam.Backup.PowerShell.Infos.VBRUniqueObject
True     False    VBRSession                               Veeam.Backup.PowerShell.Infos.VBRUniqueObject
So your solution is pretty valid :) I would actually just avoid the one-liner and do it:

Code: Select all

$Sessions = Get-VBRComputerBackupJobSession
Foreach($s in $Sessions){
Get-VBRTaskSession -Session $s
}
Main reason is it's easier to read, it's the same amount of code more or less, and then I've got the session stored at $s and can do more reporting/manipulation on it easier, but its just a personal preference, and obviously isn't quite as lean as a one-liner.

Edit: So in summary, it's because in fact it's not the equivalent one liner ;) The PS Object passed is the List result with the first, but executing it first as a sub-query passes the resulting sessions individually.
David Domask | Product Management: Principal Analyst
Suryanarayanan
Influencer
Posts: 17
Liked: 3 times
Joined: Jul 09, 2021 12:42 pm
Full Name: Suryanarayanan
Location: Bangalore India
Contact:

Re: Get last result for Windows Agent job and Tape job

Post by Suryanarayanan »

below script will work for you

Code: Select all

$job =Get-VBRComputerBackupJob
foreach ($sessions in $job) 
{ 
$jname = Get-VBRComputerBackupJobSession -Name "$($sessions.Name)?*"
$jname1=$jname| where-object {$_.EndTime -ge (Get-Date).addhours(-24)}
foreach ($session in $jname1) 
{
Get-VBRTaskSession -Session $session| Select-Object -Property Name,@{n='Jobname';e= {$($sessions.Name)}},status,@{n='StartTime';e={$_.Progress.StartTimeLocal}}, @{n='EndTime';e={$_.Progress.StopTimeLocal}},@{n='TransferedSizeinMB';e={[math]::Round(($_.Progress.TransferedSize/1048576),2)}}
}
}
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests