Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

Managing OneDrive Sharing Settings using PnP PowerShell

Posted on March 18, 2025March 18, 2025 by Rishan Solutions

Loading

OneDrive for Business allows users to share files and folders with internal and external users. PnP PowerShell provides a way to manage OneDrive sharing settings, including:

Checking current sharing settings
Enabling or disabling external sharing
Setting default sharing link types
Restricting sharing domains
Managing anonymous links


Step 1: Install and Import PnP PowerShell

If you haven’t installed PnP PowerShell, install it using:

Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force

Import the module:

Import-Module PnP.PowerShell

PnP PowerShell is ready!


Step 2: Connect to OneDrive

To manage OneDrive, first connect to it using PnP PowerShell:

$OneDriveUrl = "https://yourtenant-my.sharepoint.com/personal/your_email_com"
Connect-PnPOnline -Url $OneDriveUrl -Interactive

🔹 Replace yourtenant with your Microsoft 365 tenant name.
🔹 Replace your_email_com with your OneDrive user’s UPN (User Principal Name).
🔹 This command will prompt for Microsoft 365 login credentials.

Connected to OneDrive!


Step 3: Check Current OneDrive Sharing Settings

To view the existing sharing settings:

Get-PnPTenantSite -Url $OneDriveUrl | Select SharingCapability

🔹 The output will show the current SharingCapability value:

  • Disabled → Sharing is turned off.
  • ExistingExternalUserSharingOnly → Allows sharing only with existing external users.
  • ExternalUserSharingOnly → Allows sharing with external users with authentication.
  • ExternalUserAndGuestSharing → Allows anonymous and external sharing.

Checked OneDrive sharing settings!


Step 4: Enable or Disable External Sharing

To modify the OneDrive sharing setting:

Set-PnPTenantSite -Url $OneDriveUrl -SharingCapability ExternalUserAndGuestSharing

🔹 Replace ExternalUserAndGuestSharing with:

  • Disabled → Disable external sharing.
  • ExistingExternalUserSharingOnly → Only allow sharing with pre-invited external users.
  • ExternalUserSharingOnly → Only allow external users with authentication.
  • ExternalUserAndGuestSharing → Allow anyone with a link.

Updated OneDrive sharing settings!


Step 5: Set Default Sharing Link Type

OneDrive allows three types of default sharing links:
1️⃣ None – No default sharing link.
2️⃣ View – Read-only sharing.
3️⃣ Edit – Editable sharing link.

To set the default sharing link type:

Set-PnPTenant -DefaultSharingLinkType Edit

🔹 Replace Edit with None or View if needed.

Default sharing link type updated!


Step 6: Restrict Sharing to Specific Domains

To allow or block sharing to specific external domains:

Set-PnPTenant -SharingAllowedDomainList "trustedpartner.com,client.com" -SharingDomainRestrictionMode AllowList

🔹 This allows sharing only with trustedpartner.com and client.com.

To block specific domains:

Set-PnPTenant -SharingBlockedDomainList "untrusted.com,hacker.com" -SharingDomainRestrictionMode BlockList

Restricted OneDrive sharing domains!


Step 7: Disable Anonymous Sharing Links

To disable Anyone (anonymous) links:

Set-PnPTenant -FileAnonymousLinkType None

To enable only view-only anonymous links:

Set-PnPTenant -FileAnonymousLinkType View

Anonymous sharing links updated!


Step 8: Set Expiration for External Sharing Links

To enforce link expiration for externally shared files:

Set-PnPTenant -RequireAnonymousLinksExpireInDays 30

🔹 This ensures that external sharing links expire in 30 days.

Set expiration policy for sharing links!


Step 9: Verify Changes in Sharing Settings

After making changes, check if they were applied correctly:

Get-PnPTenant | Select DefaultSharingLinkType, SharingCapability, SharingAllowedDomainList, FileAnonymousLinkType

Verified OneDrive sharing settings!


Step 10: Disconnect the Session

Once you’re done, disconnect the session:

Disconnect-PnPOnline

Disconnected from OneDrive!

Posted Under PNP PowerShellAnonymous Links external sharing Microsoft 365 OneDrive Sharing PNP PowerShell PowerShell Automation Restrict Domains Security SharePoint online

Post navigation

Migrating Files to OneDrive using PnP PowerShell
Bulk Downloading Files from OneDrive using PnP PowerShell

Leave a Reply Cancel reply

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

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions