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

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

By:

Date:

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:

[code lang=text]
$cred = get-Credential -Message “Pass” -UserName “username@tenant.onmicrosoft.com”
Connect-PnPOnline https:/ /tenant.sharepoint.com -Credentials $cred
[/code]

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

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://staging.sharepains.com/2017/10/09/office-365-check-your-site-for-broken-links-in-sharepoint-online-part-1-2/

 

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

10 responses to “Office 365 – Check your site for broken links in SharePoint Online – Part 1”

  1. Kaycee Avatar

    Nice.. Really need it

  2. Mike Avatar
    Mike

    This is exactly what I have been looking for, is Part 2 up yet ?

    1. Pieter Veenstra Avatar

      Part 2 is on its way. It should arrive over the next few days.

  3. Dips Avatar
    Dips

    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

  4. Rick Avatar
    Rick

    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.

  5. valkuma (@valkuma) Avatar

    Do you have the full script anywhere for this? I’ve got the same pain but trying to compile the script out of these various tidbits is going to be difficult

    1. Pieter Veenstra Avatar

      Hi Valkuma, Sorry I don’t have the full script available. We never completed this project.

  6. Yann Avatar

    May I share my tool ?

    I need to regularly check my sites for dead links within SharePoint Online. I created my tool and decided to share it.

    https://blog.p-difm.com/sharepoint-online-check-for-broken-links/

    Glad if it helps

Leave a Reply

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