How to do a controlled foreach iteration

Welcome Forums General PowerShell Q&A How to do a controlled foreach iteration

Viewing 2 reply threads
  • Author
    Posts
    • #261166
      Participant
      Topics: 43
      Replies: 97
      Points: 593
      Rank: Major Contributor

      Hi All,

      in the original thread which can be found here

      the solution provided by Doug was to use a function and the below foreach.
      at this point the foreach will do 3 attempts before stopping. How can I adapt that that the code stops after the First or the Second attempt was successful?

      thanks for your assistance in this matter

      • This topic was modified 2 weeks, 6 days ago by kvprasoon. Reason: correct title
    • #261174
      Participant
      Topics: 8
      Replies: 617
      Points: 2,393
      Helping Hand
      Rank: Community Hero

      You could try checking if the command was successful with $lastexitcode and if so exit the loop with continue

      Another possible approach would be to confirm the user was removed and if so exit the loop.

    • #261206
      Participant
      Topics: 43
      Replies: 97
      Points: 593
      Rank: Major Contributor

      Thanks Doug for your reaction
      however we the 3 attempts are remaining unfortunately
      I would like to escape somehow if any of the 3 attempts was succesfull?

      Paul

      • This reply was modified 2 weeks, 6 days ago by acer460527.
Viewing 2 reply threads
  • You must be logged in to reply to this topic.