counter fails

Welcome Forums General PowerShell Q&A counter fails

Viewing 12 reply threads
  • Author
    Posts
    • #232372
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Hi

      each time when I run the below script for the first time it will go through 3 or 4 loops and then fails.
      only when I restart the script a second time it will continue as expected any Ideas?

       

    • #232414
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      What code editor do you use? Don’t you get errors? In your code line 20 you missed to provide a value expression following the ‘-‘ operator. and in you code line 21 you compare an integer with a string and you should move the condition into your while condition definietion.

      If you don’t like to use the debug tools to debug your scripts you could add some Write-Debug oder Write-Verbose (or even Write-Host) commands to your code and simply output the values of your variables to actually see what’s going on.

    • #232447
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Hi Olaf,

      that’s weird since I have the additional “-” on line 20, and I use powershell ise or visual studio code

      how would you solve line 21?

       

      Paul

    • #232480
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Assumed you actually want to decrease the $zcounter in your while loop something like this should work I think:

    • #232492
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Hi Olaf,

      I’ve got the same behaviour as previously first run it kicks out

      and the second one without changing anything finishing correctly

      any suggestions on how to get around this?

       

    • #232498
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Because you have two independend conditions you should output the two according variables. 😉

    • #232501
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Olaf,
      you lost me here 🙁

    • #232510
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      If I understood you right you don’t know what I mean, right?
      Try this:

    • #232537
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Hi Olaf,
      jikes this means that when even the counter hits 30 it will get out of the loop even when the zcounter is still counting down
      how do I solve this?

      Paul

      • This reply was modified 3 months, 3 weeks ago by acer460527.
    • #232543
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      or am I still missing the point?

      Either you or I. 😉

      Your first condition is $counter -ne $GracePeriodMin. Depending on the initial values your loop will run until $counter equals $GracePeriodMin. What are the initial values?

    • #232546
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      how do I solve this?

      What is it what you actually want to do?

    • #232555
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      Olaf,

      I start my scripts on AD and do several tasks there, then I’m moving over to AzureAD but here I have to wait because of the sync that happens every 30 min
      at this very moment the last sync has been done 20 min ago

      this means that I have to wait 11 min before I can continue with the rest of my offboarding tasks on AzureAD
      in the mean time I want to display the message that the user has to wait
      10 min
      9 min
      8 min
      ect
      and exits on -1 (31 min) to be sure that I continue with my script on 30 min +1
      that’s the goal of this script

       

    • #232591
      Participant
      Topics: 41
      Replies: 94
      Points: 560
      Rank: Major Contributor

      found the solution I changed

      to

      to solve this problem
      thanks Olaf for your help in this

Viewing 12 reply threads
  • The topic ‘counter fails’ is closed to new replies.