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.