检查网站是真正的 powershell
Checking to see a website is real powershell
我有一组 URL,我想检查它们是否是实际站点。我试过这段代码:
$Uri = $Site -as [uri]
if($Uri){
write-host $Uri
}
但是当我输入 https://acasdev.sharepoidnt.com/sites/migrations 这样的网站时
这不是一个正确的网站,它仍然输出为有效
如果您真的想测试,那里有一个资源 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
我有一组 URL,我想检查它们是否是实际站点。我试过这段代码:
$Uri = $Site -as [uri]
if($Uri){
write-host $Uri
}
但是当我输入 https://acasdev.sharepoidnt.com/sites/migrations 这样的网站时 这不是一个正确的网站,它仍然输出为有效
如果您真的想测试,那里有一个资源 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