如果以myscript.ps1 -loop -seconds 20
开头,我想循环播放我的脚本
(秒将是每个循环之间的开始 - 睡眠)。
$password = Read-Host "Enter password" -AsSecureString
的密码,所以我认为我不能使用kicker / launcher-script而不会丢失$ password变量,这样我就可以输入每个循环的pwd .. 如果将-loop
作为命名参数传递,我将如何循环播放脚本并仅循环?
我应该将整个脚本放在while循环中还是最好的方式是什么?
答案 0 :(得分:3)
使用do .. while循环,例如:
# Dot source other scripts
# Ask for and store password in a variable
do {
... # this stuff happens once or until Ctrl+C depending on $loop switch
if ($loop) { Start-Sleep -sec $seconds }
} while ($loop)
虽然不是循环切换,但你最好使用默认为1的循环计数?