Contents

Modify OneDrive Site Admins with PowerShell

Contents

In our previous post Office 365 – Access a Users OneDrive Folder we looked at giving an Admin access to a users OneDrive files. In this post we will focus on adding and removing Site Admins, on a users Personal SharePoint Site (OneDrive), using PowerShell.

First we will need to connect to SharePoint Online (see an earlier post on how to do this Connect to SharePoint Online using PowerShell

We will use the Get-SPOSite cmdlet first to see the existing Primary Site Admin on the users Personal SharePoint site:-

Get-SPOSite 'https://<tenantid>-my.sharepoint.com/personal/first_last_domain_com' | Select Owner

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_1.jpg

Waste of time hey? We can assume the Primary Site Owner will always be the OneDrive user :)

Another way of doing this is with the User Principal Name:-

Get-SPOSite -IncludePersonalSite $True -Limit All -Filter "Url -like 'my.sharepoint.com/personal/'" | Where-Object {$_.Owner -eq 'first.last@domain.com'}

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_2.jpg

We have to use a different command to find any Secondary Site Admins using the Get-SPOUser cmdlet:-

Get-SPOUser -site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com | Select LoginName,IsSiteAdmin | Where-Object {$_.IsSiteAdmin -eq 'True'}

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_4.jpg

Let us look at adding a Secondary Site Admin to the user’s Personal SharePoint Folder where “LoginName” is the user you are adding:-

Set-SPOUser -Site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com -LoginName first.last@domain.com -IsSiteCollectionAdmin $True -ErrorAction SilentlyContinue

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_5.jpg

So let us see what our Secondary Site Admin list looks like now

/images/2018/10/Access-a-Users-OneDrive-Folder_7.jpg

Great, we have two Secondary Site Admins. If required, how do we delete one of them. We run the same script as Set-SPOUser above but replace “IsSiteCollectionAdmin $True” with “IsSiteCollectionAdmin $false”:-

Set-SPOUser -Site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com -LoginName first.last@domain.com -IsSiteCollectionAdmin $false -ErrorAction SilentlyContinue

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_8.jpg

and when we use the Get-SPOUser command again, the Secondary Site Admin has been removed

/images/2018/10/Modify-OneDrive-Site-Admins-with-PowerShell_4.jpg

This is quite a handy way to give yourself temporary access to a users OneDrive folder by adding yourself as a Secondary Site Admin