How to script my output

Welcome Forums General PowerShell Q&A How to script my output

This topic contains 14 replies, has 5 voices, and was last updated by

 
Participant
4 months, 1 week ago.

  • Author
    Posts
  • #129242

    Participant
    Points: 183
    Rank: Participant

    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

     

  • #129243

    Moderator
    Points: 1,976
    Helping Hand
    Rank: Community Hero

    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
    
  • #129261

    Participant
    Points: 183
    Rank: Participant

    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'}

     

     

  • #129267

    Participant
    Points: 659
    Helping Hand
    Rank: Major Contributor

    Two ways:

    $_.Status -eq 'Warning' -or $_.Status -eq 'Critical'

    $_.Status -in 'Warning', 'Critical'

    🙂

    Check get-help about_operators for some in depth information.

  • #129276

    Participant
    Points: 183
    Rank: Participant
    $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

     

  • #129335

    Participant
    Points: 101
    Helping Hand
    Rank: Participant

    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 
  • #129344

    Participant
    Points: 183
    Rank: Participant

    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

     

     

  • #129345

    Participant
    Points: 101
    Helping Hand
    Rank: Participant

    Look at group-object

  • #129350

    Participant
    Points: 183
    Rank: Participant

    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

     

  • #129567

    Participant
    Points: 183
    Rank: Participant

    Still need help on this one.

  • #129582

    Participant
    Points: 197
    Helping Hand
    Rank: Participant

    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"
  • #129584

    Participant
    Points: 183
    Rank: Participant

    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

  • #129591

    Participant
    Points: 183
    Rank: Participant

    I got it now thanks

  • #129593

    Participant
    Points: 197
    Helping Hand
    Rank: Participant

    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"
  • #129782

    Participant
    Points: 183
    Rank: Participant

    Phansen

     

    That worked great

     

     

     

The topic ‘How to script my output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort