SharePoint Online: Set Anonymous Link Expiration Settings

Requirement: Configure Anonymous Link Expiration in SharePoint Online.

How to Set Expiry for Anonymous Links in SharePoint Online?
Anonymous links Expiration is a security best practice in SharePoint Online, This allows SharePoint Online administrators to sets the maximum expiration duration for items shared via anonymous shared links. You can set the SharePoint Online guest link expiration at the tenant level. To set anonymous links expiry days
  • Login to the SharePoint admin center, 
  • Click on Sharing >> Tick the checkbox next to "Anonymous access links expiry in this many days" and set the number of days the guest link can be active. E.g. 30
  • Click "OK" in the bottom of the page to save your changes.
sharepoint online anonymous link expiration
This enforces a mandatory expiration date setting for your anonymous links on the tenant level and determines the lifespan of anonymous shared links. If you don't set this expiry days: its default to 730 days (2 years! that's the maximum days you can set!!)

PowerShell to Set Anonymous Link Expiration in SharePoint Online:
Open SharePoint Online Management Shell and run this PowerShell script to configure guest link expiration in SharePoint Online.
#SharePoint Admin Center URL
$AdminCenterURL = "https://crescenttech-admin.sharepoint.com"

#Connect to SharePoint Online
Connect-SPOService -URL $AdminCenterURL -Credential (Get-Credential)

#Set Expiration Days for Anonymous links
Set-SPOTenant –RequireAnonymousLinksExpireInDays 30

Now, when you try to share an anonymous link, the link expiry days will be set to 30 by default (or whatever you configured). You can change the expiration date by providing a day lesser than the value configured in tenant level, But you can't set expiry date beyond the limit you set in above PowerShell script on in SharePoint Online Admin Center! This makes the link invalid after a certain number of days configured.
sharepoint online share link expiration
If you try to change the link expiration date beyond the limit set, You'll receive an error "Your organization's policy doesn't allow links to stay active for more than 30 days." This expiry days settings is applicable to both SharePoint Online and OneDrive. This minimizes the security risk.

Configure Anonymous Link Expiration Days Setting using PowerShell CSOM
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com/"
$DaysToExpire = 7

#Get Credentials to connect
$Cred= Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the Tenant
    $Tenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
    $Ctx.Load($Tenant)
    $Ctx.ExecuteQuery()

    #Set Tenant Anonymous Link Expiration Days Settings
    $Tenant.RequireAnonymousLinksExpireInDays= $DaysToExpire
    $Ctx.ExecuteQuery()

    Write-host "Anonyous Links Expiration Settings Updated Successfully!'" -f Green
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
Set the Number of Days to "0", if you never wants yours anonymous links to expire!
SharePoint Online: Set Anonymous Link Expiration Settings SharePoint Online: Set Anonymous Link Expiration Settings Reviewed by Salaudeen Rajack on September 18, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.