Get SharePoint site sharing Settings with PowerShell
Managing sharing settings for SharePoint sites is crucial for maintaining a secure and well-governed environment. With the help of PowerShell, administrators can efficiently retrieve and manage these settings across their SharePoint Online tenant. This ensures that sensitive information is not overshared and that your organisation’s data remains secure.
Importance of Reviewing Sharing Settings
Reviewing sharing settings is essential to prevent oversharing, which can lead to data breaches and unauthorized access to sensitive information. By regularly auditing and adjusting these settings, you can enforce your organization’s sharing policies and ensure that only authorized users have access to specific content. This is particularly important during the rollout of Copilot for M365, as it helps maintain a secure and compliant environment.
Refer to post Empowering Secure Collaboration: Configuring SharePoint Sharing Tenant and Site Settings with PowerShell to prevent Oversharing for more details.
Prerequisites
Before running the script, ensure you have the following:
- The PnP PowerShell module installed. You can install it using the command:
Install-Module -Name PnP.PowerShell
- Appropriate permissions to connect to the SharePoint admin center and retrieve site settings.
PowerShell Script to get sharing settings
The following PowerShell script retrieves the sharing settings for all SharePoint sites within a specified tenant and exports the data to a CSV file.
Sample PowerShell script to update sharing settings for a site
Set-PnPTenantSite -Identity https://reshmeeauckloo.sharepoint.com/sites/SharingTest `
-ShowPeoplePickerSuggestionsForGuestUsers $false `
-SharingCapability ExistingExternalUserSharingOnly `
-ExternalUserExpirationInDays 60 `
-SharingAllowedDomainList "contoso.com" `
-SharingBlockedDomainList "contoso.com" `
-SharingDomainRestrictionMode AllowList -OverrideTenantExternalUserExpirationPolicy $false `
-DefaultSharingLinkType None `
-DefaultLinkPermission None `
-DefaultShareLinkScope = SpecificPeople
-DefaultShareLinkRole = View
-DefaultLinkToExistingAccess $true `
-DisableCompanyWideSharingLinks Disabled `
-AnonymousLinkExpirationInDays 60 `
-ConditionalAccessPolicy AllowLimitedAccess `
-ReadOnlyForUnmanagedDevices $true `
-LoopDefaultSharingLinkScope SpecificPeople `
-LoopDefaultSharingLinkRole View `
-DisableSharingForNonOwners `
-OverrideSharingCapability $false `
-RequestFilesLinkEnabled $false `
-RequestFilesLinkExpirationInDays 50 `
-RestrictedAccessControl $true `
-RestrictedAccessControlGroups af8c0bc8-7b1b-44b4-b087-ffcc8df70d16
Conclusion
Regularly reviewing and adjusting sharing settings is essential to prevent oversharing and maintain a secure environment, especially during the rollout of Copilot for M365.