Quick and dirty way of checking links

So ho can we run through the site and check if links are ok on it? I mean if it is possible to automate this using powershell? Another thing here is how to do this fast, better in parallel threads. The problem here is that there is no threads in Powershell unfortunately. Thre are only Powershell Jobs, but they are quite heavy. So what to do and how to achive this? I’ve taken the idea from this post. In general i run Invoke-WebRequest cmdlet as a scriptblock in separate parallel runspaces. Here you can have a look. My contribution in this is not very big. I’ve just updated the scriptblock running as part of the thread like below:

$ScriptBlock = {
Param ($lnk)

$progressOld = $ProgressPreference
$ProgressPreference=’SilentlyContinue’
$obj = new-object psobject -prop @{Name = $lnk;
Status = (Invoke-WebRequest -Uri $lnk -DisableKeep).statuscode}

$ProgressPreference = $progressOld
$obj
}

Also i’ve added some checks to skip repeating links and links that does not start from “http*”

Advertisements
Quick and dirty way of checking links

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s