Posted On October 12, 2020

PowerShell: Test URL for Reachability

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Test URL for Reachability
function testUrl($url){
    try{
        $HTTP_Request = [System.Net.WebRequest]::Create($url)
        $HTTP_Response = $HTTP_Request.GetResponse()
        [int]$HTTP_Status = [int]$HTTP_Response.StatusCode
        If ($HTTP_Status -eq 200) {
            Write-Host "Url is reachable!" -ForegroundColor Green
            $reachable=$true
        }Else {
            Write-warning "$url is NOT unreachable!"
            $reachable=$false
        }
        If ($null -ne $HTTP_Response) {
            $HTTP_Response.Close();
        }
        return $reachable
    }catch{
        write-warning $_
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Manually Create a SSL Certificate with LetsEncrypt

Step 1: Install certbot-auto mkdir /etc/letsencryptcd /etc/letsencrypt/wget chmod a+x certbot-auto Step 2: Create the Cert…

PowerShell: Find Duplicate RDP Sessions on All Remote Desktop Servers Discovered Within the Domain

There's this module called 'PSTerminalServices' that has a method to collect active sessions on all…

Python: RegEx Module

It's been opinionated that a string operation is made complete only with RegEx. Hence, Python…