I would like to loop my script if started with myscript.ps1 -loop -seconds 20
(seconds would be the start-sleep inbetween each loop).
- The script is quite complex and i dot source two other scriptfiles
(one for functions and one for settings). - I prompt for password with
$password = Read-Host "Enter password" -AsSecureStringin the script so I don’t think I can have a kicker/launcher-script without loosing the $password variable making me input the pwd each loop..
How would I go about looping the script and ONLY loop if -loopis passed as a named parameter?
Should I put the entire script in a while-loop or what would the best way be?
Use a do .. while loop e.g.:
Although rather than a loop switch perhaps you’d be better off with a loop count that defaults to 1?