PowerShell script to check the status of a URL

后端 未结 6 672
不知归路
不知归路 2020-12-04 18:36

Similar to this question here I am trying to monitor if a set of website links are up and running or not responding. I have found the same PowerShell script over the Interne

6条回答
  •  囚心锁ツ
    2020-12-04 19:08

    You can try this:

    function Get-UrlStatusCode([string] $Url)
    {
        try
        {
            (Invoke-WebRequest -Uri $Url -UseBasicParsing -DisableKeepAlive).StatusCode
        }
        catch [Net.WebException]
        {
            [int]$_.Exception.Response.StatusCode
        }
    }
    
    $statusCode = Get-UrlStatusCode 'httpstat.us/500'
    

提交回复
热议问题