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:

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

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

 

Share
Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

View Comments

Recent Posts

Introducing 8 AI Functions for Dataverse in Power Apps

Recently Microsoft added AI Functions to Dataverse that can be used in Power Apps. In…

2 days ago

Copy and paste Scope steps in the new Power Automate Designer

One of the outstanding issues with the new Power Automate Designer is Copy and Paste…

1 week ago

Receive the available storage within your SharePoint Online tenant

Within the SharePoint admin centre there is that little detailed overview, telling you the available…

1 month ago

Options for Documenting Your Power Apps: Comments, Code, and Controls

Within Power Apps there are various ways to document your app. In this post I'm…

1 month ago

2 ways to duplicate SharePoint Lists to support your Power Apps

Recently I've been asked quite a few times to duplicate SharePoint lists as part of…

1 month ago

Update a Hyperlink Column in SharePoint with Power Automate

Today, I was asked about how to create a lookup to a document or item…

1 month ago