Removing owner from all OneDrives....

Brass Contributor

I need some help to a powershell script, that can remove an owner on all users OneDrive.

The user is added trough a 3rd party tool named ShareGate (I think by mistake) by the Sharepoint admin, so now he is owner on all OneDrive (the users are still owner too).

But I need to remove his account, and wanted to hear if any one knows a good script to do this?

13 Replies
I think you can do this by following bellow steps:
(1) This script will provide you the logic to access all the ODFBs of all the users in your tenant:
(2) Use Set-SPOSite in the following way to remove the added ODFB admin: Set-SPOUser -Site $spoODFBUrl -LoginName $Office365ODFBAdmin -IsSiteCollectionAdmin $false
best response confirmed by Jesper Stein (Brass Contributor)

Thanks for your inputs. We were lucky that Sharegate had a setting to roll back this setting so the problem is solved.

Had the same thing pop up in our tenant. This script helped resolve it, Thanks!!!

Hello Jesper, 
Do you recall the steps to roll back the administrator-owner assignment to the one drives? 


Hi Jesper, what where the exact steps in ShareGate?

I know this thread is old, but it is the closest I have seen to my problem.

I may be wrong, but I think this answer only applies to the "Secondary Admin" permission. I have the problem where an outside partner is listed as an "Owner" on all personal sites/files. His name is not listed in the admin center under the "Secondary Owner". I inherited this mess, so I can't say how he got there.

For giggles, I have tried to run the referenced script on a test site. No luck.


I have rechecked the script is working fine and you need global administrator privilege to run this script. Try the below script to remove the secondary admin privilege and before run the script change the  SecondaryAdmin ,AdminURL values 

Function Remove-OnedriveSecondaryAdmin($AdminURL,$SecondaryAdmin)
#connect Spo service.
Connect-SPOService -Url $AdminURL
#Get all Onedrive URL's.
$OneDriveURLs = Get-SPOSite -IncludePersonalSite $true -Limit All -Filter "Url -like ''"
foreach($OneDriveURL in $OneDriveURLs)
#Add Secondary administrator to Onedrive Site.
Set-SPOUser -Site $OneDriveURL.URL -LoginName $SecondaryAdmin -IsSiteCollectionAdmin $false -ErrorAction SilentlyContinue
Write-Host "Added secondary admin to the site $($OneDriveURL.URL)"
Remove-OnedriveSecondaryAdmin -SecondaryAdmin "" -AdminURL "" 

@Manidurai Mohanamariappan 

I do have Global Admin privileges.  Please clarify something that may help me.  I am under the impression that there are two "Secondary" settings that can be granted, Admin and Owner.  The script is using the admin, but I am looking to remove an owner.  


By default you can sent only one owner per site collection (Onedrive) so you can change the owner using  below script and it will remove your old owner.

Set-SPOSite -Identity -Own



@Jesper Stein  I understand this is old thread,  there is option in sharegate tool to remove name of the user from Site collection adminstrator from all one drive site, 


here is the link :

@Manidurai Mohanamariappan 



Thank you so Much! . It worked

@Jesper SteinIt seems you've solved this but there is a setting in ShareGate under Settings > Permissions & Notifications > Auto Assign as Administrator. It looks like a handy setting to turn off but it will add the user to all OneDrives within your tenancy.


After speaking to ShareGate support they sent me this link which provides a solution.