MicrosoftMicrosoft Office 365Microsoft TeamsPowershell

Control Microsoft Teams External File Sharing with PowerShell: A Guide


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.


  • 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-PnPOnline -Url "https://[yourtenant]"

3: Manage SharePoint External Sharing:

Set-PnPTenant -SharingDomainRestrictionMode AllowList -SharingAllowedDomainList "",""
  • Modify SharingDomainRestrictionMode as needed (AllowListBlockList, or None).
  • 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 guests
    • Disabled – 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.

Muhammad Faizan

Hi, My name is Muhammad Faizan and i have spent last 15 years working as System Administrator mainly with Microsoft Technologies. I am MCSE, MCTP, MCITP, certified professional. I love scripting and Powershell is the scripting language i am in love with.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button