PowerShell script exchange
Post Reply
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Failed Tape Jobs to CSV

Post by Jack1874 »

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
}
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Failed Tape Jobs to CSV

Post by veremin »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Failed Tape Jobs to CSV

Post by veremin »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Failed Tape Jobs to CSV

Post by veremin »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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*
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Failed Tape Jobs to CSV

Post by veremin »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Failed Tape Jobs to CSV

Post by PTide »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

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
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Failed Tape Jobs to CSV

Post by PTide »

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.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

I'm struggling to get it to output to CSV correctly. Could you help???
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Failed Tape Jobs to CSV

Post by PTide »

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

Thank you.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

Thanks PTide.. I don't get error messages it just doesn't write out the info correctly.

I did reference that other post yesterday .. but it still doesn't dump out the data in the way I'd like to see it.

I'll try again and post the results ...
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Failed Tape Jobs to CSV

Post by PTide »

but it still doesn't dump out the data in the way I'd like to see it.
I'll try again and post the results ...
Please include an example of how you'd like your data to appear.
Jack1874
Enthusiast
Posts: 95
Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:

Re: Failed Tape Jobs to CSV

Post by Jack1874 »

Hello, I'm looking for ...

Name State Result CreationTime EndTime
----- ----- ------ ------------ -------
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests