param($targeturi) if ($targeturi -eq $null) { Write-Host "Usage: .\checkurl.ps1 http(s)://..."; exit } # Using TLS 1.2 only for HTTPS # [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Using TLS 1.0/1.1/1.2/1.3 for HTTPS [Net.ServicePointManager]::SecurityProtocol = @([Net.SecurityProtocolType]::Tls,[Net.SecurityProtocolType]::Tls11,[Net.SecurityProtocolType]::Tls12,[Net.SecurityProtocolType]::Tls13) # Check PSVersion if ($PSVersiontable.PSVersion.Major -lt 3) { Write-Host "To use this script, you need Windows PowerShell 3.0 or later." exit } $ErrorActionPreference = "Continue" $outstr try { $httpresponse = (Invoke-WebRequest -Uri $targeturi) if ($?) { $outstr = $targeturi + "," + $httpresponse.StatusDescription + "," + $httpresponse.StatusCode } } catch { $outstr = $targeturi + ",NG," + $error[0].Exception.Message } $outstr