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

Increase Windows Management Instrumentation Service Handle Quota Limit

WMI.ps1----------------------------------------------$config = gwmi -Class "__ProviderHostQuotaConfiguration" -Namespace root$config | select -Property * -ExcludeProperty __* | ft…

Basic CSS: Use Hex Code for Specific Colors

<style>body {background-color: black;}</style>

PowerShell: Probe Remote Machine for Its OS Type

function probeOsType($server){ $ping=test-connection $server -count 1 $ttl=$ping.ResponseTimeToLive $osType=switch($ttl){ {$_ -le 64} {"Linux"; break} # MacOs…