Set expiration for anonymous links in SharePoint Online
After you have enabled anonymous links for SharePoint Online tenant, you can set a requirement that the links must expire after a certain number of days. The script sets the number of days using CSOM and Powershell.