我正在尝试阅读网站状态以确保网站正在运行。 sites在d drive中存储为csv文件。这是我的代码看起来像
#
$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()
}
答案 0 :(得分:0)
Import-Csv .\test.csv -Header "url" | foreach {
$HTTP_Request = [System.Net.WebRequest]::Create("$($_.url)")
$HTTP_Response = $HTTP_Request.GetResponse()
If([int]$HTTP_Response.StatusCode -eq 200){
Write-Host "Site is OK"
}
Else{
Write-Host "The Site is down, please check!"
}
$HTTP_Response.dispose()
}