How to script my output

I would like to just list the backup jobs that show warning or critical in the out put My Code

asnp VeeamPSSnapin

$Job = Get-VBRJob -name "MIS-M$-08-64bit"

$Session = $Job.FindLastSession()

$Session | Get-VBRTaskSession | select name, status 

The current out put is this

Name Status


ReslifeDB Warning

Webui Warning

FAReport Success

FAReportsDB Warning

Remus Success

Reslife-readyfordecommis Success

webadvisorview Critical

webadvisorview-gw Warning

webadvisorview-dev Warning

I only want to display the jobs with warning or critical status.

Any ideas?

 

thank you

 

 

 

I

 

I will give you an example, you can implement this to your code.

Get-Process | Select-Object -ExpandProperty Name,Id
Get-Process | Where-Object -FilterScript {$_.Name -eq 'PowerShell'} | Select-Object -ExpandProperty Name,Id

Thanks on my way

$Session | Get-VBRTaskSession | select name, status | Where-Object -FilterScript {$_.status -eq ‘Warning’}

This worked.

Name Status


ReslifeDB Warning

Webui Warning

FAReportsDB Warning

webadvisorview Warning

webadvisorview-gw Warning

webadvisorview-dev Warning

 

 

How can I add ‘critical’

$Session | Get-VBRTaskSession | select name, status | Where-Object -FilterScript {$_.status -eq ‘Warning’ or ‘Critical’}

 

 

Two ways:

$.Status -eq ‘Warning’ -or $.Status -eq ‘Critical’

$_.Status -in ‘Warning’, ‘Critical’

:slight_smile:

Check get-help about_operators for some in depth information.

$Session | Get-VBRTaskSession | select name, status | Where-Object -FilterScript {$_.status -eq 'Failed' -or $_.status -eq 'Warning' }

 

That worked

et-VBRTaskSession | select name, status | Where-Object -FilterScript {$.status -eq ‘Failed’ -or $.status -eq ‘Warning’ }

 

Name Status


Rum Failed

Scotch Failed

Vodka Failed

Cognac Failed

Mezcal Warning

Now how can I just get a count of each type failed warning and success

This is for a Nagios check and we have jobs that have over 20 servers if they all fail or have warnings that would be way too much data to display back to Nagios.

So I would like the output to look similar to this.

Critical Job $name 5 Servers Successful 2 Servers Warnings 1 Servers Critical

Thanks

 

Remember to filter to the left as much as possible. Might not make a great deal of difference now but further down the line with bigger more complex scripts it will save you time.

 

$Session | Get-VBRTaskSession | Where-Object -FilterScript {$_.status -eq 'Failed' -or $_.status -eq 'Warning' }| select name, status 

Alex

Yes that way works also

But I need to get the count of warning servers critical servers and success servers

 

the out put would look like this

$name is the Job Name

Critical Job $name 5 Servers Successful 2 Servers Warnings 1 Servers Critical

 

Thoughts

 

 

Look at group-object

Current code

$Session | Get-VBRTaskSession | Where-Object -FilterScript {$.status -eq ‘Failed’ -or $.status -eq ‘Warning’ }| select name, status

group-object

$Session | Get-VBRTaskSession | group-object -property status | Where-Object -FilterScript {$.status -eq ‘Failed’ -or $.status -eq ‘Warning’ }| select name, status

no output even if it did how would I format as mentioned before

 

Still need help on this one.

Try this

# sort it, so we know the index
# 0=critical, 1=success, 2=warning
$stats = $Session | Get-VBRTaskSession | Group-Object status | Sort-Object Name

"Critical Job $name $($stats[1].Count) Servers Successful $($stats[2].Count) Servers Warnings $($stats[0].Count) Servers Critical"

Thanks that worked with only one minor thing

 

 

asnp VeeamPSSnapin

$Job = Get-VBRJob -name "USAS-SpiritsMadison_StoreOnce"

$Session = $Job.FindLastSession()

# sort it, so we know the index

# 0=critical, 1=success, 2=warning

$stats = $Session | Get-VBRTaskSession | Group-Object status | Sort-Object Name

"Critical Job $name $($stats[1].Count) Servers Successful $($stats[2].Count) Servers Warnings $($stats[0].Count) Servers Critical"

Critical Job 2 Servers Successful 1Critical Servers Warnings 4 Servers

It is missing the Job name

 

Critical

I got it now thanks

Wait, there is a bug. I was focused on making it simple, so I forgot to think it through. It only works, if all three states are always present. This version is a bit longer, but should work in all cases:

$stats = $Session | Get-VBRTaskSession | Group-Object status | Sort-Object Name

$success = 0
$warning = 0
$critical = 0

foreach($stat in $stats) {
    switch($stat.Name) {
        'Success' { $success = $stat.Count; break }
        'Warning' { $warning = $stat.Count; break }
        'Critical' { $critical = $stat.Count; break }
    }
}
"Critical Job $name $success Servers Successful $warning Servers Warnings $critical Servers Critical"

Phansen

 

That worked great