Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Checking links on SharePoint page for 404 status

$
0
0

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.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>