Here's a PowerShell function that returns a hash table with all links on a page at a given URL and their status codes:
Function Get-LinksWithStatusCode
(
[string] $Url
)
{
$links = (Invoke-WebRequest -Uri $Url).Links | Select -ExpandProperty href -Unique
$hash = @{}
foreach ($link in $links)
{
Try
{
$statusCode = Invoke-WebRequest -Url $link -MaximumRedirection 0 -ErrorAction SilentlyContinue | Select -ExpandProperty StatusCode
}
Catch
{
$_
$statusCode = $_
}
$hash.Add($link, $statusCode)
}
}
I reappropriated a lot of the code from this link; it requires PowerShell v3.0. If you cannot use v3, you can use [System.Net.WebClient]
.
Also, I didn't filter out the links section to only http://*
like the blog author did. If you do this, you lose all internal links in SharePoint. I'm not sure you can execute those Invoke-WebRequest
s, so you may need to append your SPWeb.Url
onto those. Hope this helps!