Home > Application, Genel, PowerShell > Test multiple URLs with PowerShell Script

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!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: