#Update and run command to connect

$adminUPN=”adminemailhere”

$orgName=”orgname”

$userCredential = Get-Credential -UserName $adminUPN -Message “Type your password here.”

Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential

 

 

 

 

The below PowerShell command will set a mandatory 30 DAYS limit on all Anonymous links (or external sharing links) generated from SharePoint Online and OneDrive for Business.

If you do not see the parameter listed for the Set-SPOTenant command, update the SharePoint Online PowerShell to the latest version.

Set-SPOTenant -SharingCapability ExternalUserAndGuestSharing
Set-SPOTenant –RequireAnonymousLinksExpireInDays 30

 

 

 

 

 

 

 

 

 

 

 

 

 

This PowerShell command disable the expiration entirely.

Set-SPOTenant –RequireAnonymousLinksExpireInDays 0

 

 

 

 

Get-SPOTenant
identified your settings: