用于在随机时间循环中打开 URL 的 PowerShell 脚本

PowerShell Script For Opening URL On Random Time Loop

我需要一个能随机打开 3 个 URL 的 Powershell 脚本。 10 到 15 分钟之间的时间将 运行 连续直到终止任务 步骤为:

 powershell.exe -noprofile -command "Invoke-WebRequest -Uri http://your_url"

假设您只需要触发请求而不关心响应,您可以使用 Get-RandomStart-Sleep 休眠 10 到 15 分钟之间的随机间隔:

$URLs = @(
  'http://site.tld/url1'
  'http://site.tld/url2'
  'http://site.tld/url3'
)

$minSeconds = 10 * 60
$maxSeconds = 15 * 600

# Loop forever
while($true){
  # Send requests to all 3 urls
  $URLs |ForEach-Object {
    Invoke-WebRequest -Uri $_
  }

  # Sleep for a random duration between 10 and 15 minutes
  Start-Sleep -Seconds (Get-Random -Min $minSeconds -Max $maxSeconds)
}