简体   繁体   English

同时查看多个网站在线状态

[英]Checking the Online Statuses of Multiple Websites Simultaneously

I need some help with a basic PowerShell script that sends a 200 HTTP request to a website to check if it's online.我需要一些基本的 PowerShell 脚本的帮助,该脚本向网站发送 200 HTTP 请求以检查它是否在线。 I have a script that checks one website, but I need to update it in order to check multiple websites every time it runs.我有一个检查一个网站的脚本,但我需要更新它以便每次运行时检查多个网站。 I need to check 8-10 websites at a time.我需要一次检查 8-10 个网站。

Thanks.谢谢。

Here is my script so far:到目前为止,这是我的脚本:

$HTTP_Request = [System.Net.WebRequest]::Create('http://google.com')

$HTTP_Response = $HTTP_Request.GetResponse()

$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) {
    Write-Host "Site is OK!"
}
Else {
    Write-Host "The Site may be down, please check!"
}

If ($HTTP_Response -eq $null) { } 
Else { $HTTP_Response.Close() }

I tried a few things.我尝试了一些东西。 Added another HTTP_Request line, added another set of parentheses with the URL. I'm a complete novice when it comes to PowerShell, so any assistance would be greatly appreciated.添加了另一个 HTTP_Request 行,添加了另一组带有 URL 的括号。对于 PowerShell,我是一个完全的新手,所以任何帮助将不胜感激。

My approach would be to create an array of addresses and then loop through them.我的方法是创建一个地址数组,然后循环遍历它们。 I'm not great with powershell syntax but something like...我对 powershell 语法不太满意,但类似...

    $websites = @("www.google.com", "www.facebook.com", "www.amazon.com", "www.microsoft.com")

foreach ($site in $websites) {
    Test-Connection $site -Count 1 -Quiet
    if ($?) {
        Write-Host "$site is up"
    } else {
        Write-Host "$site is down"
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM