我收到“无法运行/搜索”的状态http://example.com/但对于那些以 HTTPS:// 开头的网站,没有问题,我得到的状态是 200,表示正常。我需要在脚本中添加什么,以便它也可以测试那些以 http:// 开头的网站?
下面的 powershell 脚本我试过了,对于以 HTTPS:// 开头的网站运行良好
$Uris = 'https://www.google.com/', 'https://www.yahoo.com','http://example.com/'
$PathTxt = "C:\temp\Uri.txt"
$PathCsv = "C:\temp\Uri.csv"
$uriList = @()
foreach ($uri in $Uris){
$uriObject = New-Object PSObject
Try{
$Response = Invoke-WebRequest -Uri $uri -ErrorAction Stop
$uriObject | Add-Member -MemberType NoteProperty -Name "URL" -Value $Response.BaseResponse.ResponseUri
$uriObject | Add-Member -MemberType NoteProperty -Name "Status" -Value $Response.StatusCode
$uriObject | Add-Member -MemberType NoteProperty -Name "Description" -Value $Response.StatusDescription
$uriObject | Add-Member -MemberType NoteProperty -Name "Website Name" -Value $Response.StatusDescription
Write-Host $Response.StatusCode $Response.StatusDescription $Response.BaseResponse.ResponseUri -ForegroundColor Green
$uriList += $uriObject
}
Catch{
Write-Host "Unable to reach $uri" -ForegroundColor Red
}
}
$uriList | Out-File -FilePath $PathTxt
$uriList | Export-Csv -Path $PathCsv -NoTypeInformation