Forum Discussion
Removing owner from all OneDrives....
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?
You can refer the this blog and it will be helpful for you
- 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: https://gallery.technet.microsoft.com/office/How-to-get-all-the-space-24065b8c
(2) Use Set-SPOSite in the following way to remove the added ODFB admin: Set-SPOUser -Site $spoODFBUrl -LoginName $Office365ODFBAdmin -IsSiteCollectionAdmin $false- Daniel RichardsonCopper Contributor
Had the same thing pop up in our tenant. This script helped resolve it, Thanks!!!
- Manidurai MohanamariappanIron Contributor
You can refer the this blog and it will be helpful for you
- Jesper SteinBrass Contributor
Thanks for your inputs. We were lucky that Sharegate had a setting to roll back this setting so the problem is solved.
- Willem VerwijsCopper Contributor
Hi Jesper, what where the exact steps in ShareGate?
- NCRescueTechCopper ContributorI 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.- Manidurai MohanamariappanIron Contributor
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 '-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"
- Mario SaavedraCopper Contributor
Hello Jesper,
Do you recall the steps to roll back the administrator-owner assignment to the one drives?Thanks,
Mario - UmangSoniCopper Contributor
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 : https://support-desktop.sharegate.com/hc/en-us/articles/115000647528?input_string=my+name+showing+up+with+access+to+all+users+onedrive+for+business
- Kotus-TechIron Contributor
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.
- Edwin_Tek530Copper Contributor
Prerequisites:
- SharePoint Online PowerShell module
- This script users ‘Set-SPOUser’ cmdlet. You must have the SharePoint Online global administrator permission to run the cmdlet.
Add Secondary Site Collection Admin for all OD4B Users:
Using the below Powershell script you can add the secondary site collection admin for all OD$B users.
In the script, replace the AdminURL and SecondaryAdmin with correct values.
Function Add-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 '-my.sharepoint.com/personal/'" foreach($OneDriveURL in $OneDriveURLs) { #Add Secondary administrator to Onedrive Site. Set-SPOUser -Site $OneDriveURL.URL -LoginName $SecondaryAdmin -IsSiteCollectionAdmin $True -ErrorAction SilentlyContinue Write-Host "Added secondary admin to the site $($OneDriveURL.URL)" } } Add-OnedriveSecondaryAdmin -SecondaryAdmin "email address removed for privacy reasons" -AdminURL "https://Tenantname-admin.sharepoint.com"
Remove Secondary Site Collection Admin for all OD4B Users:
To remove the secondary site collection admin, in the above script, just change the Set-SPOUser cmdlet’s parameter “IsSiteCollectionAdmin” value to $false.