【问题标题】:Checking to see a website is real powershell检查网站是真正的PowerShell
【发布时间】:2015-10-15 23:24:34
【问题描述】:

我有一组 URL,我想检查它们是否是实际站点。我试过这段代码:

$Uri = $Site -as [uri]
                                            if($Uri){
                                            write-host $Uri
                                            }

但是当我输入像https://acasdev.sharepoidnt.com/sites/migrations 这样的网站时 这不是一个正确的站点,它仍然将其输出为有效

【问题讨论】:

  • 那是因为 uri 是有效的,不管它是否引用一个实际的资源
  • 这没什么用
  • 虽然 Mathias 可能没有提供答案,但他确实解释了为什么您的方法不起作用。这很有帮助

标签: powershell url sharepoint


【解决方案1】:

如果您真的想测试,那么该 URL 处有一个资源。下面将实际尝试加载它。

try
{ 
    # First we create the request.
    $HTTP_Request = [System.Net.WebRequest]::Create('https://acasdev.sharepoidnt.com/sites/migrations')   
    # We then get a response from the site.
    $HTTP_Response = $HTTP_Request.GetResponse()

    # We then get the HTTP code as an integer.
    $HTTP_Status = [int]$HTTP_Response.StatusCode
}
catch
{
    Write-Host "It's dead Jim!"
    exit
}

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

# Finally, we clean up the http request by closing it.
$HTTP_Response.Close()

参考: Powershell Script to check the status of a URL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多