how to bail out of a bat file

Welcome Forums General PowerShell Q&A how to bail out of a bat file

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

 
Keymaster
1 year, 1 month ago.

  • Author
    Posts
  • #82429
    joe

    Participant
    Points: 0
    Rank: Member

    I have several powershell script that I use to setup an test environment, to speed things up I put them all in a bat file. Everything is fine as long as each script completes with out error. Right now each script can detect if there is a problem and post an error code, that I can pipe to a file. I can also have the script exit, but the next script in the bat file will run. Does anyone know of a way to make the powershell script exit out of the bat file (so that the next script does not run)?

    Thanks,

  • #82430

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    It can't. If you're orchestrating everything with a batch file for some reason, then it's up to the batch file to detect an error code and not run the next thing.

  • #82432

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    Me... I'd have written each "PowerShell script" as a function. Then have one script that just calls the functions. Within each function, if there's a problem, throw an error. That'll raise to the calling script and, if it doesn't Catch the error, make it bomb out.

    Or, I mean, do the same thing but keep it all in PowerShell. Same basic effect. When you call a script, if it throws an error and you don't handle it, you bomb.

    Batch files, yuck.

The topic ‘how to bail out of a bat file’ is closed to new replies.