Hey g0nzo,
Sure, lemme show you how to do this a bit more cleanly; one liners are okay, but you're asking for info from many different objects, so you need a PSCustomObject (else you get an ugly one-line of golf code...cute trick but impossible to work with.
I actually am not sure if you want all retries reported also or not, but in fact I'd advise against it, just messy. Get-VBRSession is pretty slow because it potentially works with a LOT of sessions even within one day, so instead do it like this (hacking this out quickly so take the time to play with this a bit to get the format you like)
Edit: fixed a small typo bug, just forgot to call a method and had extra letters.
Code: Select all
using namespace System.Collections.Generic
$jobs = Get-VBRJob
$LastDay = [List[Object]]@()
foreach($j in $jobs){
$sess = $j.FindLastSession()
$objects = Get-VBRJobObject -Job $j
$JobLastRunDeets = [PSCustomObject]@{
Name = $j.Name
Type = $j.JobType
StartTime = $sess.CreationTime
Result = $sess.Result
TargetRepo = $j.GetTargetRepository().Name
BackupSize = $sess.BackupStats.BackupSize/1024/1024/1024
}
$LastDay.Add($JobLastRunDeets)
}
The output is something like the below when you pipe $LastDay | Export-CSV -NoTypeInformation -Path C:\some\path\some.csv:
Code: Select all
"Name","Type","StartTime","Result","TargetRepo","BackupSize"
"vmwware-gfs","Backup","3/10/2022 13:16:09","Warning",,"0.00154495239257813"
"offloadbackup","Backup","3/10/2022 22:18:08","Failed",,"0"
"pstesting","BackupSync","3/10/2022 23:16:20","None",,"0"
"vmware-fi-nixsobr","Backup","3/10/2022 11:34:01","Success",,"0.00154495239257813"
Ignore the part about using Namespace and the [List[Object]]@() part, just please accept this is a better way to do it than += as you see a lot
(Also ignore the values for the backup size, my lab tests are done with tiny 500 MiB thin disks, so the value in GiB is really tiny!
Basically you can see that the bulk of this is building a PSCustomObject. You do that by just:
$someVar = [PSCustomObject]@{
SomeName = SomeValue
}
Make as many Names = Value combos as you like.
Because you want both session and Job data, and because Get-VBRJob is so much faster, we make a job array instead and then use the FindLastSession() method to get the same result. If you want to track retries, I believe the property IsRetryMode should give you what you want; if this is $true, then you know the job had a failure and you can flag it appropriately.
Play with the above and see what you want to be outputted.
Job Objects can be gotten with the cmdlet Get-VBRJobObject (it accepts a job as input). I don't know how your jobs are structured, but for environments I'm in that'd be 10+ objects per job, so I think not great to go in the same report, but you can design that as you like.
Get-VBRInstalledLicense maybe is what you want? Else check the other License related cmdlets. Backup proxy and repo can go into the above report I suppose, as they're part of Job objects.
Give it a whirl and see what you come up with, and ask questions.