Dear Handian Sudianto,
PowerShell provides a straightforward way to check the availability of a URL using the Invoke-WebRequest cmdlet. Below is a basic example you can use to monitor whether a website is accessible:
powershell
$Url = "https://yourwebsite.com"
try {
$Response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 10
if ($Response.StatusCode -eq 200) {
Write-Host "Website is accessible."
} else {
Write-Host "Website returned status code: $($Response.StatusCode)"
}
} catch {
Write-Host "Website is not accessible. Error: $($_.Exception.Message)"
}
a) How It Works:
- The script attempts to reach the specified URL.
If the response status code is 200, the site is considered accessible.
If the request fails or returns a different status code, the script will log the issue.
b) Optional Enhancements:
Loop through multiple URLs from a text file
Log results to a file or send email alerts
Schedule the script to run at regular intervals using Task Scheduler
I hope this helps. Just kindly tick Accept Answer that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
Best regards,
Domic Vo