Skip to main content

Hello,

It’s possible to get job status (warning, failed or success) using powershell script?

hi @hs08 

i uses MyVeeamReport.ps1

MyVeeamReport.ps1 · GitHub


I use Get-VBRJob to get the output

 

but when I try to filter only to show Type=”Vmware Backup” there is no result. Anyone know why?

 


Try this code:

Get-VBRJob | Where-Object { $_.JobType -eq "Backup" }

The column headers of the output of an array of objects in powershell do not always align to the objects’ property names. To get the correct properties for filtering, pipe a single object to “format-list” (or “fl”).


Matt's suggestion above should work to give you what you want.  The other one Link State mentioned is also very good.


@hs08,

 

If you’re ever not sure on what values are accepted, check the type for a given property by calling the GetType() method. If it’s a System.Enum, you can just call the enum names with an additional method:

 

PS C:\Users\david.LAB> $job.JobType.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True EDbJobType System.Enum


PS C:\Users\david.LAB> $job.JobType.GetType().GetEnumNames()
Backup
Replica
Copy
...

I honestly just keep a copy of this output of enums around for quick reference when making filters with Where-Object. I usually just print a list every major release to make sure it’s current and use that as a reference.

 

If you aren’t sure which is which, make a job with a known type, then just get that job by name with Get-VBRJob -Name or use the -Id (you can always get the ID from the job log for a given job -- look near the beginning of a log (search ‘new log’ and then look for JobID or Job ID)


Try this code:

Get-VBRJob | Where-Object { $_.JobType -eq "Backup" }

The column headers of the output of an array of objects in powershell do not always align to the objects’ property names. To get the correct properties for filtering, pipe a single object to “format-list” (or “fl”).

Another option to list a cmdlet’s Properties is to Pipe output with the Get-Member cmdlet. I believe this lists all Properties for a given cmdlet as well.


Hello, i want to get the ‘last Result’ and wnt to know what the header name?

I try many header parameters but not get the value.

 

 


@hs08,

There unfortunately a little trick Veeam does with Powershell where the output of Get-VBRJob has a custom view applied to the Powershell session, and some of that data is an amalgamate from a few other options.

The last result is on CBackupSession objects returned by Get-VBRBackupSession. Get-VBRBackupSession is a bit slow unless you pass Job Ids to the -Id parameter, so I’m actually going to recommend a different way:

Get-VBRSession -Type “ type of job without square brackets ]t“ | Where-Object {$_.JobId -eq $job.id} | Sort -Property CreationTime -Descending

This will return a list of job sessions with more limited information based on the JobId you pass to it. From there you can make a PSCustomObject to reflect what you want.

There are ways to get this from the CBackupJob object returned by Get-VBRJob, but you need to use unsupported methods as far as I know, so I recommend do not go that route and use supported methods.

 


Similarly, the reason that GetLastResult didn’t work for you is because that is a .NET internal method. These are unsupported methods, and I do not advise using them. Methods that are read-only like this one are typically safe to use, but it’s best to avoid them. To call them in a a Select-Object statement like you’re trying, you need to follow the example here:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.4#example-14-expandproperty-alters-the-original-object

 

Get-VBRJob | Where-Object {$_.JobType -eq “Backup”} | Select Id, Name, JobType, @{n=”Last Result”;e={$_.GetLastResult()}}

PS C:\Users\david.LAB> $job | Select Id, Name, JobType, @{n="Last Result";e={$_.GetLastResult()}}

Id Name JobType Last Result
-- ---- ------- -----------
3713a1dd-8ff5-4a6d-ac24-4e89d348fffb dd-malware-box-backup Backup Success


 


@ddomask 

Super…., it’s work by execute

Get-VBRJob | Where-Object {$_.JobType -eq “Backup”} | Select Id, Name, JobType, @{n=”Last Result”;e={$_.GetLastResult()}}


You’re welcome hs08, but do remember, this is an unsupported method, so if there is _any_ weirdness with it, as per Support Policy (5.8) no support for such unsupported methods.

It will work and probably will not change, but I cannot guarantee that it won’t, so I advise build your script with the PSCustomObject and Get-VBRBackupSession + Get-VBRJob as noted.


Great to see you figured out the correct syntax for the PS command and it now works.  👍


Comment