1

How can I execute two PowerShell commands such that I only send text to the prompt once and the second command executes only after the first command has executed successfully?

3
  • 2
  • I suggest you share your code and tell us why it doesn't work as you'd like. You may need one of the suggestions from @Bob's comment or we may be able to fiddle with your pipeline to get similar results.
    – uSlackr
    Mar 15, 2012 at 14:45
  • I don't have anything to share, as I had no idea how to do it, and my search efforts failed.
    – lance
    Mar 15, 2012 at 14:48

1 Answer 1

1

Try this:

[command1] ; if ($Lastexitcode -eq 0) { [command2] }

This executes command1 and then command2 if $Lastexitcode equals 0. If command1 produces an error, it should throw that error and stop executing anyway (if it is a powershell command - if not, it depends).

Is this what you were looking for?

Edit: The links in Bobs comment also deliver detailed solutions to your question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .