SharePoint Online: How to Remove Shared Links
Requirement: Remove a share link in SharePoint Online.
How to Remove Share Links in SharePoint Online?
You may have shared specific files or folders with people who don’t have access to the SharePoint Online site through the Share feature (either through the toolbar button or from the context menu), and there may be times when you want to remove a share link (E.g., You want to prevent users from accessing a folder which was shared accidentally). You can remove the shared link to stop users from accessing it. This article will show you how to remove the sharing link from a folder or document so others cannot access it.
Delete a Shared link in SharePoint Online
If a document or folder is shared with specific users, you can remove individual user access from it. If it’s shared with anyone, you have to delete the shared link.
- Browse to your SharePoint Online Document library, where the file or folder you want to remove shared links.
- Right-click on the File/Folder, and Select “Manage Access” from the context menu.
- In the Manage Access popup, To remove users from the shared link, click the drop-down next to users >> Click on the X button next to the user you wish to remove the access from. You’ll be prompted to confirm.
- Similarly, to remove a link shared with everyone, click on the little three dots for “More options”>> Click on the X button next to the link to delete the share link completely.
- Confirm the prompt by clicking on the “Delete link” button.
Once the share link has been removed, anyone who tries to use the link will receive an error message, “This link has been removed. Sorry, access to this document has been removed. Please contact the person who shared it with you.”
As a side note, Users may get this error page when the shared link for the file or folder has expired, too.
Can I remove all shared links in one stretch programmatically?
Unfortunately, No as of today. Although you can remove shared links from item permissions, that leaves the link in an unhealthy state with an error message “This link is broken. Delete it and share the item again.”.
#Remove All "Shared Links" of the Item
$ItemPermission = Get-PnPListItemPermission -List $ListName -Identity $Item.Id
$ItemPermission.Permissions | Where {$_.PrincipalName.StartsWith("SharingLinks")} | ForEach-Object {
$Item.RoleAssignments.GetByPrincipalId($_.PrincipalId).DeleteObject()
Invoke-PnPQuery
}