Test multiple URLs with PowerShell Script

If you are a web application administrator or you are building infrastructure, you may need to work with many URLs and test them at the same time.

This script allows you to create URLs with .txt documents or web address parameters you write and test them with Internet Explorer or Chrome. It also allows you to get test results as .log.

Please do not hesitate to contact me if you need a similar script or if you have any problems.
Do not forget to follow 🙂

2018-06-27_11-51-29

#Script starts here

#Get country and language codes with fr/fr format
#$counlang = Get-Content ‘C:\script\counlang.txt’
# Test Country and Language
$counlang = “noo/no”,”no/no”,”fi/en”,”fi/tr”

# Get url prefix from .txt file
$urlprefix = Get-Content ‘C:\script\prefix.txt’
#Test url prefix
#$urlprefix = “”http://www””

$urlpart1 = “.iistest.com:80/”
$urlpart2= “/search/gui/”

# Get Product name from .txt file
#$product = Get-Content ‘C:\script\products.txt’
# Test product
$product = “a”

# example URL
#http://www.iistest.com:80/dk/en/search/gui/a

# Lets start one by one
“___________________________________________________________________________________” | Out-File -Append ‘C:\script\urlout.txt’
“______________________________Start________________________________________________” | Out-File -Append ‘C:\script\urlout.txt’
“___________________________________________________________________________________” | Out-File -Append ‘C:\script\urlout.txt’
$counlang | ForEach-Object {
$line = $_
$urlprefix | ForEach-Object {
$prefix = $_
$url = $prefix+$urlpart1+$line+$urlpart2+$product
$url

$urlresult = Invoke-WebRequest -Uri $url -Method ‘HEAD’ -ErrorAction SilentlyContinue -ErrorVariable urlerror
$urlresult
$urlerror
$status = $urlresult | Select-Object StatusCode
if ($urlerror)
{
$outdate = (Get-Date).ToString()
# if url doesnt work add KO
$outformat = $outdate+” “+$url+” “+”KO”
$outformat | Out-File -Append ‘C:\script\urlout.txt’
}
else
{
$outdate = (Get-Date).ToString()
# if url working add OK
$outformat = $outdate+” “+$url+” “+”OK”
$outformat | Out-File -Append ‘C:\script\urlout.txt’
}
# Open URL, you can chose all method, one or never
# Open URL with Google Chrome

#start-process -FilePath ‘C:\Program Files (x86)\Google\Chrome\Application\chrome.exe’ -ArgumentList $url

# Open URL with Internet Explorer
#$IE=new-object -com chrome.application
#$IE.navigate2($url)
#$IE.visible=$true

}

}
“___________________________________________________________________________________” | Out-File -Append ‘C:\script\urlout.txt’
“______________________________Finish_______________________________________________” | Out-File -Append ‘C:\script\urlout.txt’
“___________________________________________________________________________________” | Out-File -Append ‘C:\script\urlout.txt’

#Script finish here

Enjoy!

2 Replies to “Test multiple URLs with PowerShell Script”

  1. Can u please post a powershell script which tests few URL’s and prints their output in HTML table format. table contains URL and its status.

    1. Dear Kalpana,

      Thank you for your interest in the article. I developed these codes for my customer. I cannot access the source URL anymore. Please can you share me some URLs or xmls, I can help you.

      Kind regards,
      Murat

Leave a Reply

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