Powershell: I need to exit the Switch and Try and continue the Loop

Microsoft Windows

Active Members
Joined
Dec 10, 2024
Messages
24,663
I have a condition embedded in a Loop, Try, Switch and if the condition is met, I want to gracefully exit the Loop iteration and go onto the next Loop value. I’m trying to use the Break however that command is exiting the Switch command not the loop iteration. Please assist.In the following sample of my actual code, Whenever the Orange or Green conditions are met, exit the loop and check the next color- do not execute the rest of the Loop code:$colors = @(“Red”,”Orange”,”Yellow”,”Green”,”Blue”,”Indigo”,”Violet”) :ExitLoop For ($i=0; $i -lt $colors.Length; $i++) { Try {

Continue reading...
 
Back
Top