PowerShell script exchange
Post Reply
fborges555
Lurker
Posts: 1
Liked: never
Joined: Apr 28, 2022 1:14 pm
Full Name: Fernando Borges
Contact:

Veeam Job and last Result

Post by fborges555 »

Hi gurus

I am very new to powershell, so go easy on me , I am looking to export to csv the name or the job and to get the last result(success or fail)

I got so far the follwoing

$result= Get-vbrJob
this brings the two information I need ,how do I go and pull ONLY the name of the job and GetLastResult to an csv file
foreach ($jobname in $result){ select $jobname.name , $jobname.getlastresult | export-csv c:\temp\file.csv}
I tried a foreach loop but I get number instead of the string I want.

thanks a bunch for any help
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Job and last Result

Post by oleg.feoktistov »

Hi Fernando,

Should be as simple as that:

Code: Select all

$jobs = Get-VBRJob
$summary = @()
foreach ($job in $jobs) {
 $lastResult = $job.GetLastResult()
 $summary += $job | select Name, @{n='LastResult';e={$lastResult}}
}
$summary | export-csv C:\Temp\file.csv
Please also note that using methods is not supported, so it is not guaranteed that, for example, GetLastResult() will work in the next release. A fully supported script would look like this:

Code: Select all

$jobs = Get-VBRJob
$sessions = Get-VBRBackupSession
$summary = @()
foreach ($job in $jobs) {
  $lastSession = $sessions | where {$_.JobId -eq $job.Id} | sort -Property EndTime | select -Last 1
  $summary += $job | select Name, @{n='LastResult';e={$lastSession.Result}}
}
$summary | export-csv C:\Temp\file.csv
Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests