Transferring OneDrive Ownership using PnP PowerShell

Loading

In Microsoft 365, when an employee leaves the organization, administrators may need to transfer ownership of their OneDrive files to another user. This ensures that business-critical data is not lost and can be accessed by the appropriate person.

Using PnP PowerShell, administrators can quickly transfer OneDrive ownership and assign new permissions.

What You’ll Learn:

Connect to SharePoint Admin Center using PnP PowerShell
Find the OneDrive URL of a User
Grant Access to Another User
Verify the Permission Changes


Step 1: Install and Import PnP PowerShell

Ensure you have PnP PowerShell installed. If not, install it:

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

Then, import the module:

Import-Module PnP.PowerShell

PnP PowerShell is ready!


Step 2: Connect to SharePoint Admin Center

To manage OneDrive ownership, first connect to the SharePoint Admin Center:

$AdminSiteUrl = "https://yourtenant-admin.sharepoint.com"
Connect-PnPOnline -Url $AdminSiteUrl -Interactive

🔹 Replace “yourtenant” with your actual Microsoft 365 tenant name.
🔹 This command will prompt you to sign in with admin credentials.

Connected to SharePoint Admin Center!


Step 3: Get OneDrive URL of the User

Each OneDrive site follows a standard URL pattern:

Get-PnPUserProfileProperty -Account "user@yourdomain.com" | Select -ExpandProperty PersonalUrl

🔹 Replace user@yourdomain.com with the current owner’s email.

OneDrive URL retrieved!


Step 4: Grant Access to the New Owner

Now, grant full control to the new owner:

$OneDriveUrl = "https://yourtenant-my.sharepoint.com/personal/user_domain_com"
$NewOwner = "newowner@yourdomain.com"

Connect-PnPOnline -Url $OneDriveUrl -Interactive
Set-PnPAzureADUser -Identity $NewOwner -IsSiteCollectionAdmin $true

🔹 Replace “user_domain_com” with the current OneDrive owner’s UPN format.
🔹 Replace newowner@yourdomain.com with the new owner’s email.

New owner granted full control!


Step 5: Remove Old Owner (Optional)

If necessary, remove the previous owner’s permissions:

Remove-PnPAzureADUser -Identity "oldowner@yourdomain.com"

🔹 Replace oldowner@yourdomain.com with the previous owner’s email.

Old owner’s access removed!


Step 6: Verify the Changes

To check the new permissions:

Get-PnPSiteCollectionAdmin

This will display the current OneDrive site collection administrators.

Ownership transfer verified!


Step 7: Disconnect the Session

Once done, disconnect the session:

Disconnect-PnPOnline

Disconnected successfully!

Leave a Reply

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