Forum Discussion
John_Dodo
Dec 07, 2022Brass Contributor
exit powershell scriptS when imbricated
 Hello,     I have a script main.ps1 called with parameters "-environment PRD" or "-environment  "PILOT".     This main script calls a toolbox.ps1 script which is like this :    switch ($environment) ...
AndySvints
Dec 11, 2022Iron Contributor
Hello John_Dodo,
One of the quick & dirty and pretty simple option would be to throw an exception.
Something like this:
switch ($environment) {
            "PILOT" {
                #define PILOT vars
            }
            "PRD" {
                #define PRD vars
            }
            default {
                throw "!!! No Environment provided !! Closing the script."
            }
        }It will generate terminating error and will end you child and main scripts.
Hope that helps.
Thank you.
- John_DodoDec 12, 2022Brass Contributor
Hi AndySvints ,
it seems to work indeed, though it is "quick n dirty" as you mentionned 🙂
I'll use this method for the moment and see if I can find something cleaner in the future.
Thank you.