Sep 01 2017 03:27 AM
Sep 01 2017 03:27 AM
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?
Sep 01 2017 03:53 AM
Sep 01 2017 05:46 AMSolution
You can refer the this blog and it will be helpful for you
Sep 03 2017 11:25 PM
Thanks for your inputs. We were lucky that Sharegate had a setting to roll back this setting so the problem is solved.
Dec 12 2017 06:36 AM
Had the same thing pop up in our tenant. This script helped resolve it, Thanks!!!
Sep 21 2018 02:32 PM
Do you recall the steps to roll back the administrator-owner assignment to the one drives?
Mar 07 2019 11:43 PM - edited Mar 07 2019 11:44 PM
Hi Jesper, what where the exact steps in ShareGate?
Apr 05 2019 09:10 AM
Apr 05 2019 11:21 PM
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
#connect Spo service.
Connect-SPOService -Url $AdminURL
#Get all Onedrive URL's.
$OneDriveURLs = Get-SPOSite -IncludePersonalSite $true -Limit All -Filter "Url -like '-my.sharepoint.com/personal/'"
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 "Admin@contoso.onmicrosoft.com" -AdminURL "https://Contoso-admin.sharepoint.com"
Apr 09 2019 07:00 AM
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.
Apr 12 2019 01:20 AM - edited Apr 12 2019 01:21 AM
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 https://contoso-my.sharepoint.com/personal/user_contoso_onmicrosoft_com -Own
May 13 2019 09:34 PM
@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,
Mar 30 2020 02:53 AM
@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.