• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

Running a script based on the output of Powershell

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?
  • 2
1 Solution
If 'FAIL' is a real output, not just a write-host, then:

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

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

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.
Brent ChallisPrincipal: ITCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now