SOLVED

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?

14 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: 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
best response confirmed by Jesper Stein (Brass Contributor)
Solution

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? 

Thanks, 
Mario

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.

@NCRescueTech 

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" 

@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.  

@NCRescueTech 

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
er admin@contoso.onmicrosoft.com

 

 

@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...

@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.

@Kotus-Tech 

 

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.

 
1 best response

Accepted Solutions
best response confirmed by Jesper Stein (Brass Contributor)