Prerequisite: Connect Microsoft 365 Service in Powershell
By default, when you click the Copy Link button in a Sharepoint Site, it generates a new link with everyone internal with the link access. The script below can change the default behavior to be to generate a direct link for those who already have access.
#Variables
$AdminCenterURL = "https://<tenant-name>.sharepoint.com"
$HubSiteURL = "https://<hub-site-url>.com"
#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive
#Get the children of the main HubSite
$Hub = Get-PnPHubSiteChild -Identity $HubSiteURL
foreach ($Url in $Hub)
{
#Remove the "Same as organization-level" setting. Can be set to anything Internal, None or Direct.
Set-PnPTenantSite -Url $Url -DefaultSharingLinkType Internal
#Set the Default Link type to be Existing Access
Set-PnPTenantSite -Url $Url -DefaultLinkToExistingAccess $true
}
Script Source: https://www.ssw.com.au/rules/change-link-sharing-default-behaviour/