Powershell Script to monitor Website status

Handian Sudianto 6,541 Reputation points
2025-08-18T06:39:34.3366667+00:00

Anyone know how to make powershell to monitor accessible of URL?

I want to monitor if the website is accessible or not.

Windows for business | Windows Server | Performance | Windows desktop and shell experience
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Domic Vo 11,150 Reputation points Independent Advisor
    2025-08-24T14:35:09.12+00:00

    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

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.