We have to check all the links on a SharePoint webpart page owned by our safety division.
There are are almost 100 links on the page, and we'd like to use PowerShell to find the links with 404 status / Not Found.
So far I have a simple script such as:
$downloadURL = 'https://MySharePointSite/Pages/Documents%20and%20Forms.aspx'
$downloadRequest = Invoke-WebRequest -Uri $downloadURL -UseDefaultCredentials -
$downloadRequest.Links
...the output is great, but I'm still not getting Status Code to find 404s
Would I loop on each link to get status?
$downloadURL = 'https://MySharePointSite/Pages/Documents%20and%20Forms.aspx'$downloadRequest = Invoke-WebRequest -Uri $downloadURL -UseDefaultCredentials
$allLinks = $downloadRequest.Links | Select innerText, href | Format-table -AutoSize
$allLinks
foreach ($link in $allLinks)
{
$statusCode = Invoke-WebRequest -Uri $link.href
$statusCode
}
I'm getting error:
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.