PowerShell script exchange
Post Reply
macp2153
Novice
Posts: 4
Liked: 1 time
Joined: Jun 27, 2018 1:03 pm
Full Name: Paul MacDonald
Contact:

script to report failure or warning and reason

Post by macp2153 »

Hi I am very new to powershell, when I finally get some time I am going to try and teach myself since it seems to be a very useful tool for Veeam backup. I am trying to create a powershell script that will list the warnings or failure from the night before and list the reason. I have found some snippets of code on here and can list the name of the server, the status and the error, I would like to add a timestamp for each job as well. Here is what I have so far:

Code: Select all

asnp VeeamPSSnapin
$vbrsessions = Get-VBRBackupSession | ?{$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).adddays(-1) -and $_.result -eq "warning"}
foreach ($session in $vbrsessions)
{
    foreach ($failedVM in $session.GetTaskSessionsByStatus("warning"))
    {
       write-host $failedVM.Name, $FailedVM.status, $FailedVM.info.reason
    }
}  
output:

Code: Select all

cus3-vfs05 Warning pre-freeze script finished execution with exit code 4
Cus6x-Tfs2 Warning pre-freeze script finished execution with exit code 6
Cus61-MatFs08 Warning pre-freeze script finished execution with exit code 3
Cus61-NprFs06 Warning pre-freeze script finished execution with exit code 4
Cus3-Vfs08 Warning pre-freeze script finished execution with exit code 4
Rcunv61f-Fs01 Warning pre-freeze script finished execution with exit code 8
CUS61-NPRFS02 Warning pre-freeze script finished execution with exit code 4
DevMtx-Fs04 Warning pre-freeze script finished execution with exit code 8
cus61-matfs01 Warning pre-freeze script finished execution with exit code 3
Cus3-vfs02 Warning pre-freeze script finished execution with exit code 4
Csmt-MatFs01 Warning pre-freeze script finished execution with exit code 4
Cus61-MatFs07 Warning pre-freeze script finished execution with exit code 3
DevMtx-Fs03 Warning pre-freeze script finished execution with exit code 4
Cus6x-TmatFs01 Warning pre-freeze script finished execution with exit code 3
Cus61-MatUnv Warning pre-freeze script finished execution with exit code 3
Cus61-MatFs05 Warning pre-freeze script finished execution with exit code 3
cus61-nprfs01 Warning pre-freeze script finished execution with exit code 4
cus3-vfs01 Warning pre-freeze script finished execution with exit code 4
CUS61-MATFS02 Warning pre-freeze script finished execution with exit code 3
cus61-nprunv Warning pre-freeze script finished execution with exit code 4
DevMtx-Pp01 Warning pre-freeze script finished execution with exit code 4
Cus61-MatFs04 Warning pre-freeze script finished execution with exit code 3
DevMtx-Fs05 Warning pre-freeze script finished execution with exit code 4
AR6XF-FS01 Warning pre-freeze script finished execution with exit code 3
Cus61-MatFs06 Warning pre-freeze script finished execution with exit code 3
Cus61-NprFs03 Warning pre-freeze script finished execution with exit code 4
DevMtx-Fs01 Warning pre-freeze script finished execution with exit code 8
Dev616F-Fs02 Warning pre-freeze script finished execution with exit code 4
Cus61-MatFs03 Warning pre-freeze script finished execution with exit code 3
AR6XN-FS03 Warning pre-freeze script finished execution with exit code 3
DevMtx-Fs02 Warning pre-freeze script finished execution with exit code 4
veremin
Product Manager
Posts: 20408
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: script to report failure or warning and reason

Post by veremin »

What exactly you mean by timestamp? Job start time? Job end time? Time when VM was successfully processed? Something else?

By the way, have you seen this PowerShell report; might be something you're looking for?

Thanks!
macp2153
Novice
Posts: 4
Liked: 1 time
Joined: Jun 27, 2018 1:03 pm
Full Name: Paul MacDonald
Contact:

Re: script to report failure or warning and reason

Post by macp2153 »

Job start time would work. Thanks
veremin
Product Manager
Posts: 20408
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: script to report failure or warning and reason

Post by veremin »

You can get job start time from a from backup session:

Code: Select all

$BackupSession.CreationTime
VM processing start time - from a task session:

Code: Select all

$TaskSession.info.QueuedTime
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests