Office 365 – Check your site for broken links in SharePoint Online – Part 1

On Tech Community I came across a question about how to  check for broken links on your SharePoint sites in SharePoint Online.

So I’m first starting with the connection to a site collection in Office 365 using PnP PowerShell:

$cred = get-Credential -Message "Pass" -UserName "username@tenant.onmicrosoft.com"
Connect-PnPOnline https:/ /tenant.sharepoint.com -Credentials $cred

Then to check if a url exists I’m running:

invoke-webrequest $url -DisableKeepAlive -UseBasicParsing -Method head

this returns the following for a valid request:

StatusCode : 200
StatusDescription : OK
Content :
RawContent : HTTP/1.1 200 OK
Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
x-ms-request-id: afdbecd9-02c3-419c-8677-94ef...
Forms :
Headers : {[Pragma, no-cache], [Strict-Transport-Security, max-age=31536000; includeSubDomains], [X-Content-Type-Options,
nosniff], [X-Frame-Options, DENY]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 0

So now I just have to go through all sites and all the lists and libraries in my site to collect all the urls from the content. First looping through all the sites.

$web = Get-PnPWeb
Get-WebForBrokenLinks -Web $web
ForEach ($subweb in $subwebs)
{
Get-WebForBrokenLinks -Web $subweb
}

I will go through the content in part 2 of this series where I will implement the Get-WebForBrokenLinks function that will use the invoke-webrequest.

 

In the meanwhile there is also a uservoice  that needs up voting: https://sharepoint.uservoice.com/forums/330318-sharepoint-administration/suggestions/10208799-broken-link-checker

Part 2 of this series can be found here:

https://veenstra.me.uk/2017/10/09/office-365-check-your-site-for-broken-links-in-sharepoint-online-part-1-2/

 

Advertisements

9 thoughts on “Office 365 – Check your site for broken links in SharePoint Online – Part 1

  1. Hi

    PS doesn’t seem to recognise Get-WebForBrokenLinks – how do I overcome this?? I have module SharePointPnPPowerShellOnline v 2.28.18 installed

    Can anyone help please.

    Thanks

    Like

  2. It seems to me that as long as the site collection part of the URL is valid, the Invoke-WebRequest returns 200. If the rest of the URL is actually not valid, it still returns 200, giving you a false positive.

    Like

Please leave a comment or feedback

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.