Other toolsPowerShell

M365 – Remove Anonymous Links (PowerShell)

Remove anonymous sharing links in Microsoft 365.

PowerShell
Connect-PnPOnline -Url https://contoso.sharepoint.com -Interactive
$items = Get-PnPUnifiedGroup -IncludeSiteUrl
foreach ($g in $items) {
  Set-PnPSite -Url $g.SiteUrl -DisableSharingForNonOwners
}
  

From Joseph Nakhle's automation workbench.

More Other tools scripts