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

PowerShell: Purge User Outlook Profile

# Purge-User-Outlook-Profile.ps1# Set folder path$folderToDelete="$env:localappdata\Microsoft\Outlook";function purgeFolder($path){ mkdir c:\temp -force -ea SilentlyContinue | out-null cd c:\temp…

PowerShell: Automatically Fix SQL Server by Killing Long Running Queries

# autofixSqlLongRunningQueries.ps1 # version 0.01 # This version is limited to SQL Server Localhost execution,…

PowerShell: Alternative to Test-NetConnection for Legacy Windows

This little snippet is useful as a helper function to quickly determine port connectivity between…