Powershell – Loop script until user chooses to exit

Question:

How can I start a script over again? I have 3 switches and I want them to revert back to the beginning of the script.

So after See dsquery.txt saved to Desktop.” I want it to go back to write-host portion.

Answer:

My personal favorite for checking user input is the do { } until () loop. Here is your code with the added loop, this will accomplish what your looking for:

This is a pretty unique strategy in my opinion. I took this from Jerry Lee Ford’s book : Microsoft Windows PowerShell Programming for the absolute beginner

you can read more about these and every other loop in powershell here : http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/

Source:

Powershell – Loop script until user chooses to exit by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply