我对编码还不熟悉,但是我遇到了需要一段代码的问题。我需要计算一下此脚本运行的次数。由于它需要停止,因此需要将上述计数保存到其他位置,因此,我为什么认为它需要转到单独的文件中。我尝试用简单的英语键入步骤,希望有人可以帮助我将其放入Powershell。
open a file
print number it has
look at the number
if it is <=2
than increase the number by 1 in file
end
if it is =3
than wait 10 minutes
change number to 1 in file
end
所以这应该完全按照您的要求进行。但是,它糟糕透顶且开始睡眠是最糟糕的方法。您可能需要查看Register-ScheduledJob
$Filepath = "C:/myfile.txt"
$Counter = Get-Content -Path $Filepath
#To echo it to the command line
$Counter
If ($Counter -le 2){
$NewCounter = $Counter + 1
Set-Content -Path $Filepath -Value $NewCounter
}
elseif ($Counter -ge 3) {
Start-Sleep -Seconds 600
$NewCounter = 1
Set-Content -Path $Filepath -Value $NewCounter
}