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

RSiddiqui 5 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 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,931 Reputation points Microsoft External Staff
    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.

    1 person found this answer helpful.

Your answer

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