• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • 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?
0
redman20111
Asked:
redman20111
  • 2
1 Solution
 
soostibiCommented:
If 'FAIL' is a real output, not just a write-host, then:

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

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

0
 
soostibiCommented:
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.
0
 
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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