Skip to content

Instantly share code, notes, and snippets.

@terremoth
Created March 15, 2026 05:04
Show Gist options
  • Select an option

  • Save terremoth/0469d579c6438d5a5accabd5b997c2b3 to your computer and use it in GitHub Desktop.

Select an option

Save terremoth/0469d579c6438d5a5accabd5b997c2b3 to your computer and use it in GitHub Desktop.
Check website list file, one per line, to se if it is online
param(
[string]$FilePath
)
if (-not (Test-Path $FilePath)) {
Write-Host "File not found: $FilePath" -ForegroundColor Red
exit
}
$sites = Get-Content $FilePath
foreach ($site in $sites) {
$site = $site.Trim()
if ([string]::IsNullOrWhiteSpace($site)) {
continue
}
if ($site -notmatch '^https?://') {
$url = "http://$site"
} else {
$url = $site
}
try {
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "HEAD"
$request.AllowAutoRedirect = $false
$request.Timeout = 5000
$response = $request.GetResponse()
$statusCode = [int]$response.StatusCode
if ($statusCode -ge 300 -and $statusCode -lt 400) {
$redirect = $response.Headers["Location"]
Write-Host "$site SUCCESS (REDIRECT to: $redirect)" -ForegroundColor Green
}
elseif ($statusCode -eq 200) {
Write-Host "$site SUCCESS" -ForegroundColor Green
}
else {
Write-Host "$site FAIL" -ForegroundColor Red
}
$response.Close()
}
catch {
try {
if ($site -notmatch '^https?://') {
$url = "https://$site"
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "HEAD"
$request.AllowAutoRedirect = $false
$request.Timeout = 5000
$response = $request.GetResponse()
$statusCode = [int]$response.StatusCode
if ($statusCode -ge 300 -and $statusCode -lt 400) {
$redirect = $response.Headers["Location"]
Write-Host "$site SUCCESS (REDIRECT to: $redirect)" -ForegroundColor Green
}
elseif ($statusCode -eq 200) {
Write-Host "$site SUCCESS" -ForegroundColor Green
}
else {
Write-Host "$site FAIL" -ForegroundColor Red
}
$response.Close()
}
else {
Write-Host "$site FAIL" -ForegroundColor Red
}
}
catch {
Write-Host "$site FAIL" -ForegroundColor Red
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment