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:-
1 |
Get-SPOSite 'https://<tenantid>-my.sharepoint.com/personal/first_last_domain_com' | Select Owner |
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:-
1 |
Get-SPOSite -IncludePersonalSite $True -Limit All -Filter "Url -like 'my.sharepoint.com/personal/'" | Where-Object {$_.Owner -eq '[email protected]'} |
We have to use a different command to find any Secondary Site Admins using the Get-SPOUser cmdlet:-
1 |
Get-SPOUser -site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com | Select LoginName,IsSiteAdmin | Where-Object {$_.IsSiteAdmin -eq 'True'} |
Let us look at adding a Secondary Site Admin to the user’s Personal SharePoint Folder where “LoginName” is the user you are adding:-
1 |
Set-SPOUser -Site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com -LoginName [email protected] -IsSiteCollectionAdmin $True -ErrorAction SilentlyContinue |
So let us see what our Secondary Site Admin list looks like now
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”:-
1 |
Set-SPOUser -Site https://<tenant-id>-my.sharepoint.com/personal/first_last_domain_com -LoginName [email protected] -IsSiteCollectionAdmin $false -ErrorAction SilentlyContinue |
and when we use the Get-SPOUser command again, the Secondary Site Admin has been removed
This is quite a handy way to give yourself temporary access to a users OneDrive folder by adding yourself as a Secondary Site Admin
Pingback: Office 365 - Access a Users OneDrive Folder
Great post.
Thank you!