我正在尝试读取网站状态以确保网站正在运行。站点作为 csv 文件存储在 d 驱动器中。这是我的代码的样子
#
$file = "C:\Config\script.csv"
$csv = Import-Csv $file -Header "url" |select -expand url |%{ [System.Net.Webrequest]::Create("$_")}
foreach ($row in $csv) {
$HTTP_Request = [System.Net.WebRequest]::Create("$_")
$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 is down, please check!"
}
$HTTP_Response.Close()
}