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

问题描述 投票:0回答:1

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

 powershell.exe -noprofile -command "Invoke-WebRequest -Uri http://your_url"
powershell command-prompt
1个回答
1
投票

假设您只需要触发请求而不关心响应,则可以使用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)
}
© www.soinside.com 2019 - 2024. All rights reserved.