PowerShell script exchange
Jack1874
Enthusiast
Posts: 95 Liked: 5 times
Joined: Oct 17, 2015 3:32 pm
Full Name: Stuart Little
Location: Canada
Contact:
Post
by Jack1874 » Feb 22, 2016 3:19 pm
this post
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:
Post
by veremin » Feb 22, 2016 3:52 pm
this post
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:
Post
by Jack1874 » Feb 22, 2016 4:26 pm
this post
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:
Post
by veremin » Feb 22, 2016 4:31 pm
this post
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:
Post
by Jack1874 » Feb 22, 2016 4:53 pm
this post
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:
Post
by veremin » Feb 22, 2016 4:58 pm
this post
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:
Post
by Jack1874 » Feb 22, 2016 5:09 pm
this post
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
veremin
Product Manager
Posts: 20400 Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:
Post
by veremin » Feb 22, 2016 5:42 pm
this post
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:
Post
by Jack1874 » Feb 23, 2016 2:44 pm
this post
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:
Post
by Jack1874 » Feb 23, 2016 3:32 pm
this post
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:
Post
by PTide » Feb 23, 2016 4:40 pm
this post
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:
Post
by Jack1874 » Feb 23, 2016 6:06 pm
this post
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:
Post
by PTide » Feb 23, 2016 6:40 pm
this post
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:
Post
by Jack1874 » Feb 23, 2016 9:37 pm
this post
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:
Post
by PTide » Feb 23, 2016 9:47 pm
this post
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:
Post
by Jack1874 » Feb 24, 2016 3:09 pm
this post
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:
Post
by PTide » Feb 24, 2016 3:43 pm
this post
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:
Post
by Jack1874 » Feb 24, 2016 7:38 pm
this post
Hello, I'm looking for ...
Name State Result CreationTime EndTime
----- ----- ------ ------------ -------
Users browsing this forum: No registered users and 8 guests