How to Remove SharePoint File Shared Links: Approach Overview and Sample Implementations


πŸ“Œ What Is It?

SharePoint offers a convenient way to collaborate by allowing users to share files and folders using shareable links. These links can be set with various permission levels, such as view-only, edit, or full control. Shareable links can either be internal (accessible only within the organization) or external (available to anyone with the link, including guests).

While sharing links is helpful for collaboration, it can create security vulnerabilities if not properly managed. Over time, files might remain shared with external or inactive users, potentially exposing sensitive information. Therefore, removing shared links is a critical practice for data protection and access control.


πŸ’‘ Why Do We Need to Remove Shared Links?

Shared links, although practical, can introduce risks when left unmanaged. Here’s why removing them is necessary:

  1. πŸ”’ Data Security:
    When files are shared externally or with unauthorized users, they remain accessible until the shared links are removed. By deleting these links, you ensure that only users with explicit permissions can access the files. This is especially important for confidential or business-critical information, such as contracts, financial records, or client data.
  2. βš–οΈ Compliance and Governance:
    Many organizations need to comply with data protection regulations such as GDPR, HIPAA, or SOX. These regulations often require organizations to manage file access carefully. Periodically removing shared links ensures that only compliant and authorized access remains.
  3. πŸ‘₯ Access Control and Revocation:
    When employees leave the company or move to different teams, they may still have access to shared links. Removing these links prevents lingering access by deprovisioned or unauthorized users, reducing the risk of data leaks.
  4. 🧹 Cleanup and Maintenance:
    Over time, SharePoint environments accumulate orphaned or unused shared links. Regularly removing them helps maintain a clean and organized environment, preventing unnecessary link sprawl.

πŸ‘₯ Who Uses It?

Removing shared links is a practice employed by various roles across organizations, including:

  • IT Administrators:
    IT admins often remove shared links as part of data security policies or regular audits. They use tools like PowerShell scripts or Microsoft Graph API to automate link removal on a larger scale.
  • Compliance and Governance Teams:
    Organizations with strict data governance policies need to ensure that file sharing complies with regulations. Removing outdated or unauthorized shared links is part of their security audits and compliance checks.
  • SharePoint Site Owners:
    Site owners manage access to their content and regularly review shared links to prevent unintended access. They often rely on the SharePoint Online interface to remove links for individual files or folders.
  • End Users:
    Individual employees may need to remove shared links they’ve created, especially when they no longer wish to share files. For example, users might revoke access to outdated documents shared with external collaborators.

πŸ”§ What Applications Use It?

SharePoint shared link management applies across several Microsoft applications, including:

  • SharePoint Online:
    The primary platform where users share and manage files. Removing shared links in SharePoint is essential for controlling access and safeguarding content.
  • OneDrive for Business:
    Since OneDrive uses the same Microsoft 365 sharing architecture as SharePoint, the process of managing shared links is identical. Users frequently share OneDrive files externally, making it equally important to remove unused or insecure links.
  • Microsoft Graph API:
    Organizations with custom applications or DevOps pipelines can use Graph API to automate link management. This is useful for large-scale operations or integrating with external platforms.
  • Power Automate:
    Power Automate workflows can automatically remove or expire shared links based on specific triggers, such as a file reaching a certain age or no longer being in use.

βœ… Prerequisites

Before you start removing shared links, ensure you meet the following prerequisites:

  1. Permissions:
    • You must have Full Control or Site Collection Administrator privileges to remove shared links.
    • For PowerShell or Graph API, you need SharePoint Administrator or Global Administrator permissions.
    • For Power Automate workflows, you need Microsoft 365 licensing with Power Automate access.
  2. Admin Center Access:
    • To manually remove shared links, you need access to the Microsoft 365 Admin Center or SharePoint Admin Center.
    • For PowerShell, install and authenticate with SharePoint Online Management Shell or PnP PowerShell.
  3. PowerShell Modules Installed:
    • If using PowerShell, install the SharePoint Online Management Shell module:
    powershellCopyEditInstall-Module -Name Microsoft.Online.SharePoint.PowerShell
  4. Identify Shared Links:
    • Before removing links, identify which files or folders have shared links. You can do this manually or use PowerShell scripts to list all shared links.

πŸš€ Approaches to Remove Shared Links
1. Manual Removal via SharePoint Online Interface

Best for: Small-scale link removal.

Steps:

  1. Go to SharePoint Online and navigate to the site library containing the shared file or folder.
  2. Locate the file or folder and click the β€œShare” button.
  3. In the Manage Access panel, you will see a list of shared links.
  4. Select the β€œX” or β€œRemove” button next to the shared link to delete it.
  5. Confirm the removal action.

βœ… Pros:

  • Simple and intuitive for individual file management.
  • No technical expertise required.

❌ Cons:

  • Time-consuming for bulk link removal.
  • Lacks advanced filtering or reporting capabilities.

2. PowerShell Approach

Best for: Bulk removal or automation.

Prerequisites:

  • Install the SharePoint Online Management Shell module and authenticate:
Connect-SPOService -Url "https://<YourTenant>-admin.sharepoint.com"

Script to Remove All Shared Links in a Document Library:

$siteUrl = "https://<YourTenant>.sharepoint.com/sites/YourSite"
Connect-PnPOnline -Url $siteUrl -UseWebLogin

# Retrieve all files with shared links
$items = Get-PnPListItem -List "Documents" -PageSize 1000

foreach ($item in $items) {
    $linkDetails = Get-PnPProperty -ClientObject $item -Property HasUniqueRoleAssignments
    if ($linkDetails -eq $true) {
        Write-Host "Removing shared links for: $($item['FileLeafRef'])"
        Set-PnPListItemPermission -List "Documents" -Identity $item.Id -RemoveSharingLink
    }
}

βœ… Pros:

  • Efficient for bulk removal.
  • Reusable and customizable script.
  • Ideal for large-scale operations.

❌ Cons:

  • Requires PowerShell knowledge.
  • Potential risk of errors without validation.

3. Microsoft Graph API Approach

Best for: Large-scale automation and integration with custom applications.

Steps:

  1. Register an app in Azure AD and obtain the Client ID, Tenant ID, and Client Secret.
  2. Use the following Graph API endpoint to remove shared links:
DELETE https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/permissions/{permission-id}

βœ… Pros:

  • Ideal for large-scale automated operations.
  • Suitable for integration with external systems.

❌ Cons:

  • Requires Azure AD registration and permissions.
  • More complex to set up.

4. Power Automate Workflow

Best for: Automated removal based on specific triggers.

Steps:

  1. Go to Power Automate β†’ Create Flow.
  2. Select the trigger: β€œWhen a file is created or modified”.
  3. Add the action: β€œRemove sharing link”.
  4. Define conditions (e.g., remove links older than 30 days).
  5. Save and run the flow.

βœ… Pros:

  • Automated and continuous removal.
  • No coding required.

❌ Cons:

  • Requires Power Automate premium.
  • Less flexible than PowerShell.

πŸ”₯ Best Practices
  • Schedule Regular Audits: Use PowerShell or Power Automate to automate regular audits.
  • Use Expiration Dates: Apply expiration dates to external links for automatic removal.
  • Backup Before Bulk Operations: Always back up your SharePoint data before bulk link removal.
  • Enforce Policies: Use Information Protection labels for consistent governance.

πŸ”— References

Removing SharePoint shared links is essential for data security, compliance, and access management. By using the right tools and best practices, you can efficiently manage and secure your SharePoint environment.


Authentication Automation Backup Batching Compliance Content Type CSS Extensions Flows Google GULP Javascript Limitations Metadata MFA Microsoft Node NodeJs O365 OneDrive Permissions PnP PnPJS Policy Power Automate PowerAutomate PowerShell React ReactJs Rest API Rest Endpoint Send an HTTP Request to SharePoint SharePoint SharePoint List SharePoint Modern SharePoint Online Sharing Is Caring SPFX SPO Sync Tags Teams Termstore Versioning WebParts

Leave a Comment

Your email address will not be published. Required fields are marked *