Failed Tape Jobs to CSV

PowerShell script exchange

Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Mon Feb 22, 2016 3:19 pm

Guys, is there a way that we could do the following ...

- list all D2T (tape) jobs with either a failed or warning
- select last 31 days \ month
- export to a CSV
- email out

We currently have the following but its not exactly what we are looking for ...

Can anyone help?

Code: Select all
asnp "VeeamPSSnapIn"
$arrJobNames = @("D2T-Job01", "D2T-Job02")

foreach ($Job in $arrJobNames) {
$TapeJob = Get-VBRTapeJob -Name $Job
$LastSession = Get-VBRSession -job $TapeJob -Last | Format-Table @{Label="Job Name";Expression={$Job}},State,Result,CreationTime,EndTime -AutoSize
Write-Output $LastSession
}
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby v.Eremin » Mon Feb 22, 2016 3:52 pm

I don't have an access to a console at the moment, but session filter should look similar to the following:

Code: Select all
$LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-30) -and $_.State -eq "Failed" -or $_.State -eq "Warning"}


As to CSV and notification parts, feel free to use these - articles as a source for inspiration.

CSV & Notification

Thanks.
v.Eremin
Veeam Software
 
Posts: 13260
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Mon Feb 22, 2016 4:26 pm

Thanks... I ran it and got the the following error ...

Code: Select all
At line:1 char:102
+ ... ddays(-30) -and $._State -eq "Failed" -or $._State -eq "Warning"}
+                    ~
You must provide a value expression following the '-and' operator.
At line:1 char:103
+ ... days(-30) -and $._State -eq "Failed" -or $._State -eq "Warning"}
+                    ~~~~~~~~
Unexpected token '$._State' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby v.Eremin » Mon Feb 22, 2016 4:31 pm

I've made a typo in the provided example (it happens when writing scripts without access to the console :) ). Try the updated version:

Code: Select all
$LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-30) -and $_.State -eq "Failed" -or $_.State -eq "Warning"}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13260
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Mon Feb 22, 2016 4:53 pm

No worries.. really appreciate your help here ...

Am I doing something wrong? I used the new command but got this ..

Code: Select all
Get-VBRSession : Cannot validate argument on parameter 'Job'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:1 char:36
+ $LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Da ...
+                                    ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-VBRSession], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.GetVBRSession
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby v.Eremin » Mon Feb 22, 2016 4:58 pm

The message says that $TapeJob variable is a null object, thus, the session cannot be gotten for it.

Have you incorporated the modified line inside your original script?

Code: Select all
asnp "VeeamPSSnapIn"
$arrJobNames = @("D2T-Job01", "D2T-Job02")

foreach ($Job in $arrJobNames) {
$TapeJob = Get-VBRTapeJob -Name $Job
$LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-30) -and $_.State -eq "Failed" -or $_.State -eq "Warning"} | Format-Table @{Label="Job Name";Expression={$Job}},State,Result,CreationTime,EndTime -AutoSize
Write-Output $LastSession
}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13260
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Mon Feb 22, 2016 5:09 pm

Got it now... I missed a line n the original code.

Is there anyway to ask it to select all jobs when building the array.. other than having to list them all off? All our Tape jobs start D2T

Code: Select all
$arrJobNames = @("D2T*
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby v.Eremin » Mon Feb 22, 2016 5:42 pm

May be something like?

Code: Select all
asnp "VeeamPSSnapIn"
foreach ($TapeJob in Get-VBRTapeJob | where {$_.name -like "D2T*"}) {
$LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-30) -and $_.State -eq "Failed" -or $_.State -eq "Warning"} | Format-Table @{Label="Job Name";Expression={$Job}},State,Result,CreationTime,EndTime -AutoSize
Write-Output $LastSession
}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13260
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Tue Feb 23, 2016 2:44 pm

Hello, I've ran the script several times and even though it runs I get no out put on the screen. I even tried changed it eq success.. but still nothing.

Any ideas?

Code: Select all
asnp "VeeamPSSnapIn"
foreach ($TapeJob in Get-VBRTapeJob | where {$_.name -like "D2T*"}) {
    $LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-1) -and $_.State -eq "Success" -or $_.State -eq "Warning"} | Format-Table @{Label="Job Name";Expression={$Job}},State,Result,CreationTime,EndTime -AutoSize
    Write-Output $LastSession
    }
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Tue Feb 23, 2016 3:32 pm

I broke the script out and and I can get the $TapeJob to populate.

Then when I run the Get-VBRSession line I get ...

Code: Select all
Get-VBRSession : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.PowerShell.Infos.VBRJob' required by parameter 'Job'. Specified method is not supported.
At line:1 char:21
+ Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-1) ...
+                     ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-VBRSession], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Cmdlets.GetVBRSession
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby PTide » Tue Feb 23, 2016 4:40 pm

Hi,

even though it runs I get no out put on the screen. I even tried changed it eq success.. but still nothing.

<...>
Code: Select all
$LastSession = Get-VBRSession -job $TapeJob | where {$_.CreationTime -ge (Get-Date).adddays(-1) -and $_.[b]State[/b] -eq "Success" -or $_.[b]State[/b] -eq "Warning"} | Format-Table @{Label="Job
<...>


Please try to replace "State" with "Result", as there is no "Success" value for the "State" field.

Thank you.
PTide
Veeam Software
 
Posts: 3019
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Tue Feb 23, 2016 6:06 pm

Thanks Ptide.. that works great.

Would you know how to have that info sent out via email? I could figure it our myself but if its something that you know how to do quickly I'd really appreciate it
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby PTide » Tue Feb 23, 2016 6:40 pm

Just export your final CSV to Export-Csv cmdlet and email it:

Code: Select all
 .... | Export-Csv -Path <temp csv path> -NoTypeInformation
Send-MailMessage -Body ("see attach") -From <> -SmtpServer <> -Subject "B&R result" -To <> -Attachments <temp csv path>


Thank you.
PTide
Veeam Software
 
Posts: 3019
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Re: Failed Tape Jobs to CSV

Veeam Logoby Jack1874 » Tue Feb 23, 2016 9:37 pm

I'm struggling to get it to output to CSV correctly. Could you help???
Jack1874
Enthusiast
 
Posts: 88
Liked: 4 times
Joined: Sat Oct 17, 2015 3:32 pm
Location: Canada
Full Name: Stuart Little

Re: Failed Tape Jobs to CSV

Veeam Logoby PTide » Tue Feb 23, 2016 9:47 pm

Do you get error messages? If so please refer to this post.

Thank you.
PTide
Veeam Software
 
Posts: 3019
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Next

Return to PowerShell



Who is online

Users browsing this forum: dcheung and 3 guests