Categories
Web

Powershell check link list

This PowerShell script can be used to check the status of a plain list of web links that you have copied to your clipboard.

In my case, I have the following links from my blog.

https://web-performance.ch/
https://web-performance.ch/blog/
https://web-performance.ch/technical-books-for-it-engineering-architecture/
https://web-performance.ch/kontakt/
https://web-performance.ch/security/sans-internet-storm-center-api/
https://web-performance.ch/azure/azure-front-door-configuring-tls-cipher/
https://web-performance.ch/monitoring/identify-your-statuscake-calls/
https://web-performance.ch/azure/amazing-icon-downloader-for-portal-azure-com/
https://web-performance.ch/web/notepad-remove-empty-lines/
https://web-performance.ch/web/atlassian/jira-confluence-server-redirect-to-cloud/
https://web-performance.ch/category/ai/
https://web-performance.ch/category/web/atlassian/
https://web-performance.ch/category/azure/
https://web-performance.ch/category/general/
https://web-performance.ch/category/monitoring/
https://web-performance.ch/category/news/
https://web-performance.ch/category/security/
https://web-performance.ch/category/sitecore/
https://web-performance.ch/category/web/
https://web-performance.ch/category/web-performance/

I am utilizing this script; I run it in ISE. Once you run it, it will take all the links from your clipboard and test the HTTP response status code.

$urls = Get-Clipboard -TextFormatType Text | Out-String -Stream

foreach ($url in $urls) {
    $url = $url.Trim()
    if ($url -ne "") {
        try {
            # Attempt to request the URL without following redirects
            $response = Invoke-WebRequest -Uri $url -UseBasicParsing -Method Get -TimeoutSec 15 -MaximumRedirection 0 -ErrorAction SilentlyContinue
            # Output the URL and status code for successful requests
            Write-Output "$url - $($response.StatusCode)"
        } catch {
            # Attempt to catch redirection or other web request errors
            $statusCode = $_.Exception.Response.StatusCode.value__
            $statusDescription = $_.Exception.Response.StatusDescription
            # Output the URL and the status code for errors, including redirects
            Write-Output "$url - $statusCode $statusDescription"
        }
    }
}

Here is the full example output from the ISE console when running it. All the links in my list returned a status code of 200, indicating success.

PS C:\Users\webperformance> $urls = Get-Clipboard -TextFormatType Text | Out-String -Stream

foreach ($url in $urls) {
    $url = $url.Trim()
    if ($url -ne "") {
        try {
            # Attempt to request the URL without following redirects
            $response = Invoke-WebRequest -Uri $url -UseBasicParsing -Method Get -TimeoutSec 15 -MaximumRedirection 0 -ErrorAction SilentlyContinue
            # Output the URL and status code for successful requests
            Write-Output "$url - $($response.StatusCode)"
        } catch {
            # Attempt to catch redirection or other web request errors
            $statusCode = $_.Exception.Response.StatusCode.value__
            $statusDescription = $_.Exception.Response.StatusDescription
            # Output the URL and the status code for errors, including redirects
            Write-Output "$url - $statusCode $statusDescription"
        }
    }
}
https://web-performance.ch/ - 200
https://web-performance.ch/blog/ - 200
https://web-performance.ch/technical-books-for-it-engineering-architecture/ - 200
https://web-performance.ch/kontakt/ - 200
https://web-performance.ch/security/sans-internet-storm-center-api/ - 200
https://web-performance.ch/azure/azure-front-door-configuring-tls-cipher/ - 200
https://web-performance.ch/monitoring/identify-your-statuscake-calls/ - 200
https://web-performance.ch/azure/amazing-icon-downloader-for-portal-azure-com/ - 200
https://web-performance.ch/web/notepad-remove-empty-lines/ - 200
https://web-performance.ch/web/atlassian/jira-confluence-server-redirect-to-cloud/ - 200
https://web-performance.ch/category/ai/ - 200
https://web-performance.ch/category/web/atlassian/ - 200
https://web-performance.ch/category/azure/ - 200
https://web-performance.ch/category/general/ - 200
https://web-performance.ch/category/monitoring/ - 200
https://web-performance.ch/category/news/ - 200
https://web-performance.ch/category/security/ - 200
https://web-performance.ch/category/sitecore/ - 200
https://web-performance.ch/category/web/ - 200
https://web-performance.ch/category/web-performance/ - 200