Running a script based on the output of Powershell

Posted on 2011-05-11
Last Modified: 2012-05-11
Interesting Powershell job I'd like to run, not sure the best way to implement this.

There is a PS command I run to get an output, which is either PASS or FAIL.

Test-Myjob -server Server1

If the Output is FAIL, then I'd like to run a remediation script to fix this

Remediation.ps1 Server1

Any ideas?
Question by:redman20111
    LVL 13

    Accepted Solution

    If 'FAIL' is a real output, not just a write-host, then:

    if((Test-Myjob -server Server1) -eq "FAIL"){Remediation.ps1 Server1}


    Author Comment

    Thanks, not sure what you mean by the difference between a real output or write-host?

    LVL 13

    Expert Comment

    If you run this:

    "hello world" | get-member

    Open in new window

    This will run, as get-member will receive input from the previos expression.

    If you run this

    write-host "hello world" | get-member

    Open in new window

    Will give you an error, because write-host does not provide an output, even if you see the text on the console. 'Output' something that travels in the pipeline.
    LVL 8

    Expert Comment

    You need check the code for the Test-Myjob script to see if it is using Write-Host or Write-Output.  Write-Host goes straight to the screen, Write-Output goes to the pipeline.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Group Policy Delegation Recently, I was tasked with delegating permissions for a specific group of administrators to a specific list of Group Policy Objects(GPO). A couple of things need to happen here for this to work. If you want the Administrat…
    "Migrate" an SMTP relay receive connector to a new server using info from an old server.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now