MicrosoftMicrosoft Office 365Microsoft TeamsPowershell
Control Microsoft Teams External File Sharing with PowerShell: A Guide
Table of Contents
Introduction
Microsoft Teams empowers collaboration, but it’s essential to manage how files and content are shared with individuals outside your organization. PowerShell provides precise control over external sharing settings, ensuring your data remains secure.
Prerequisites
- Basic understanding of Microsoft Teams administration
- Familiarity with PowerShell scripting
- Access to Microsoft Teams admin center
Understanding External Sharing Settings
Before using PowerShell, it’s helpful to understand the types of external sharing settings available within Teams:
- SharePoint: Governs file-sharing within team channels, connected to the team’s underlying SharePoint site.
- OneDrive: Controls sharing for files stored in a user’s individual OneDrive for Business.
Managing External Sharing with PowerShell
1: Install the Teams and SharePoint Online Modules:
Install-Module -Name MicrosoftTeams
Install-Module -Name SharePointPnPPowerShellOnline
2: Connect to Teams and SharePoint:
Connect-MicrosoftTeams
Connect-PnPOnline -Url "https://[yourtenant]-admin.sharepoint.com"
- Replace “[yourtenant]” with your actual tenant name.
3: Manage SharePoint External Sharing:
Set-PnPTenant -SharingDomainRestrictionMode AllowList -SharingAllowedDomainList "contoso.com","fabrikam.com"
- Modify
SharingDomainRestrictionMode
as needed (AllowList
,BlockList
, orNone
). - Update
SharingAllowedDomainList
with domains you want to allow (comma-separated).
4: Manage OneDrive External Sharing:
Set-SPOTenant -SharingCapability ExternalUserAndGuestSharing
- Use other values for
SharingCapability
to restrict further:ExternalUserSharingOnly
– Only share with existing guestsDisabled
– Disable all external sharing
Real-World Scenarios
- Enforce Approved Domains: Share only with specific partner organizations.
- Limit Sensitive Projects: Restrict external sharing on teams containing highly confidential data.
- Temporary Contractor Access: Enable external sharing temporarily, then disable it when a project concludes.
Important Considerations
- Organization-wide sharing settings must be configured to allow for team-level controls.
- Carefully balance collaboration needs with your organization’s data security policies.