Can we do a bulk deletion of all the links which are accessible to "anyone in the organisation" ?

RSiddiqui 0 Reputation points
2024-11-14T02:19:01.1933333+00:00

Hi,

Could you please confirm if it's possible to remove all links or a bulk deletion of links associated with files (within a specific folder or site) that are currently accessible to "Anyone in the organization"?

If this is possible, could you kindly provide the steps or method for doing so?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,197 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,067 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 47,626 Reputation points Microsoft Vendor
    2024-11-14T09:43:03.7133333+00:00

    Per my research, it is not possible to remove all anyone links associated with files in a SharePoint Online document library.

    Currently, you could remove all shared links associated with files in a SharePoint Online document library through PNP PowerShell.

    #Define Parameters
    $SiteURL= "https://crescent.sharepoint.com/sites/IT"
    $ListName = "Documents"
        
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -UseWebLogin
     
    #Get All items from List
    $Items = Get-PnPListItem -List $ListName -PageSize 2000
     
    #Iterate though each item in the list
    ForEach($Item in $Items) {
        #Get Shared links of the item
          $HasUniquePermissions = Get-PnPProperty -ClientObject $Item -Property "HasUniqueRoleAssignments"
            If($HasUniquePermissions) {
                $RoleAssignments = Get-PnPProperty -ClientObject $Item -Property RoleAssignments
                ForEach($RoleAssignment in $RoleAssignments) {
                    Get-PnPProperty -ClientObject $RoleAssignment -Property RoleDefinitionBindings, Member               
                    If($RoleAssignment.Member.Title -like "SharingLinks*") {
                        Remove-PnPGroup -Identity $RoleAssignment.Member.Title -Force
                        Write-host "Removed $($RoleAssignment.Member.Title) from $($Item.FieldValues.FileRef)"
                    }
                }
            }          
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.