SOLVED

Removing owner from all OneDrives....

%3CLINGO-SUB%20id%3D%22lingo-sub-102727%22%20slang%3D%22en-US%22%3ERemoving%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-102727%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20some%20help%20to%20a%20powershell%20script%2C%20that%20can%20remove%20an%20owner%20on%20all%20users%20OneDrive.%3C%2FP%3E%3CP%3EThe%20user%20is%20added%20trough%20a%203rd%20party%20tool%20named%20ShareGate%20(I%20think%20by%20mistake)%20by%20the%20Sharepoint%20admin%2C%20so%20now%20he%20is%20owner%20on%20all%20OneDrive%20(the%20users%20are%20still%20owner%20too).%3C%2FP%3E%3CP%3EBut%20I%20need%20to%20remove%20his%20account%2C%20and%20wanted%20to%20hear%20if%20any%20one%20knows%20a%20good%20script%20to%20do%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-102727%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOneDrive%20for%20Business%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-417827%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-417827%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3058%22%20target%3D%22_blank%22%3E%40Manidurai%20Mohanamariappan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20have%20Global%20Admin%20privileges.%26nbsp%3B%20Please%20clarify%20something%20that%20may%20help%20me.%26nbsp%3B%20I%20am%20under%20the%20impression%20that%20there%20are%20two%20%22Secondary%22%20settings%20that%20can%20be%20granted%2C%20Admin%20and%20Owner.%26nbsp%3B%20The%20script%20is%20using%20the%20admin%2C%20but%20I%20am%20looking%20to%20remove%20an%20owner.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-401182%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-401182%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F314987%22%20target%3D%22_blank%22%3E%40NCRescueTech%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20rechecked%20the%20script%20is%20working%20fine%20and%20you%20need%20global%20administrator%20privilege%20to%20run%20this%20script.%20Try%20the%20below%20script%20to%20remove%20the%20secondary%20admin%20privilege%20and%20before%20run%20the%20script%20change%20the%26nbsp%3B%26nbsp%3BSecondaryAdmin%20%2CAdminURL%20values%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CPRE%3EFunction%20Remove-OnedriveSecondaryAdmin(%24AdminURL%2C%24SecondaryAdmin)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23connect%20Spo%20service.%3CBR%20%2F%3EConnect-SPOService%20-Url%20%24AdminURL%3CBR%20%2F%3E%23Get%20all%20Onedrive%20URL's.%3CBR%20%2F%3E%24OneDriveURLs%20%3D%20Get-SPOSite%20-IncludePersonalSite%20%24true%20-Limit%20All%20-Filter%20%22Url%20-like%20'-my.sharepoint.com%2Fpersonal%2F'%22%3CBR%20%2F%3Eforeach(%24OneDriveURL%20in%20%24OneDriveURLs)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23Add%20Secondary%20administrator%20to%20Onedrive%20Site.%3CBR%20%2F%3ESet-SPOUser%20-Site%20%24OneDriveURL.URL%20-LoginName%20%24SecondaryAdmin%20-IsSiteCollectionAdmin%20%24false%20-ErrorAction%20SilentlyContinue%3CBR%20%2F%3EWrite-Host%20%22Added%20secondary%20admin%20to%20the%20site%20%24(%24OneDriveURL.URL)%22%20%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3ERemove-OnedriveSecondaryAdmin%20-SecondaryAdmin%20%22Admin%40contoso.onmicrosoft.com%22%20-AdminURL%20%22https%3A%2F%2FContoso-admin.sharepoint.com%22%26nbsp%3B%3C%2FPRE%3E%3C%2FBLOCKQUOTE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-400937%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-400937%22%20slang%3D%22en-US%22%3EI%20know%20this%20thread%20is%20old%2C%20but%20it%20is%20the%20closest%20I%20have%20seen%20to%20my%20problem.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20may%20be%20wrong%2C%20but%20I%20think%20this%20answer%20only%20applies%20to%20the%20%22Secondary%20Admin%22%20permission.%20I%20have%20the%20problem%20where%20an%20outside%20partner%20is%20listed%20as%20an%20%22Owner%22%20on%20all%20personal%20sites%2Ffiles.%20His%20name%20is%20not%20listed%20in%20the%20admin%20center%20under%20the%20%22Secondary%20Owner%22.%20I%20inherited%20this%20mess%2C%20so%20I%20can't%20say%20how%20he%20got%20there.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20giggles%2C%20I%20have%20tried%20to%20run%20the%20referenced%20script%20on%20a%20test%20site.%20No%20luck.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-363143%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-363143%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Jesper%2C%20what%20where%20the%20exact%20steps%20in%20ShareGate%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-260472%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-260472%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Jesper%2C%26nbsp%3B%3CBR%20%2F%3EDo%20you%20recall%20the%20steps%20to%20roll%20back%20the%20administrator-owner%20assignment%20to%20the%20one%20drives%3F%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%26nbsp%3B%3CBR%20%2F%3EMario%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136367%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136367%22%20slang%3D%22en-US%22%3E%3CP%3EHad%20the%20same%20thing%20pop%20up%20in%20our%20tenant.%20This%20script%20helped%20resolve%20it%2C%20Thanks!!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-103075%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-103075%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20your%20inputs.%20We%20were%20lucky%20that%20Sharegate%20had%20a%20setting%20to%20roll%20back%20this%20setting%20so%20the%20problem%20is%20solved.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-102765%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-102765%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20refer%20the%20this%20blog%20and%20it%20will%20be%20helpful%20for%20you%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-102732%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-102732%22%20slang%3D%22en-US%22%3EI%20think%20you%20can%20do%20this%20by%20following%20bellow%20steps%3A%3CBR%20%2F%3E(1)%20This%20script%20will%20provide%20you%20the%20logic%20to%20access%20all%20the%20ODFBs%20of%20all%20the%20users%20in%20your%20tenant%3A%20%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FHow-to-get-all-the-space-24065b8c%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FHow-to-get-all-the-space-24065b8c%3C%2FA%3E%3CBR%20%2F%3E(2)%20Use%20Set-SPOSite%20in%20the%20following%20way%20to%20remove%20the%20added%20ODFB%20admin%3A%20Set-SPOUser%20-Site%20%24spoODFBUrl%20-LoginName%20%24Office365ODFBAdmin%20-IsSiteCollectionAdmin%20%24false%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-443264%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-443264%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F314987%22%20target%3D%22_blank%22%3E%40NCRescueTech%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBy%20default%20you%20can%20sent%20only%20one%20owner%20per%20site%20collection%20(Onedrive)%20so%20you%20can%20change%20the%20owner%20using%26nbsp%3B%20below%20script%20and%20it%20will%20remove%20your%20old%20owner.%3C%2FP%3E%3CP%3ESet-SPOSite%20-Identity%20%3CA%20href%3D%22https%3A%2F%2Fcontoso-my.sharepoint.com%2Fpersonal%2Fuser_devsvr_onmicrosoft_com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcontoso-my.sharepoint.com%2Fpersonal%2Fuser_contoso_onmicrosoft_com%3C%2FA%3E%20-Own%3CBR%20%2F%3Eer%20admin%40contoso.onmicrosoft.com%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-565548%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-565548%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F56139%22%20target%3D%22_blank%22%3E%40Jesper%20Stein%3C%2FA%3E%26nbsp%3B%20I%20understand%20this%20is%20old%20thread%2C%26nbsp%3B%20there%20is%20option%20in%20sharegate%20tool%20to%20remove%20name%20of%20the%20user%20from%20Site%20collection%20adminstrator%20from%20all%20one%20drive%20site%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ehere%20is%20the%20link%20%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fsupport-desktop.sharegate.com%2Fhc%2Fen-us%2Farticles%2F115000647528%3Finput_string%3Dmy%2Bname%2Bshowing%2Bup%2Bwith%2Baccess%2Bto%2Ball%2Busers%2Bonedrive%2Bfor%2Bbusiness%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport-desktop.sharegate.com%2Fhc%2Fen-us%2Farticles%2F115000647528%3Finput_string%3Dmy%2Bname%2Bshowing%2Bup%2Bwith%2Baccess%2Bto%2Ball%2Busers%2Bonedrive%2Bfor%2Bbusiness%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1199465%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1199465%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3058%22%20target%3D%22_blank%22%3E%40Manidurai%20Mohanamariappan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20Much!%20.%20It%20worked%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1263930%22%20slang%3D%22en-US%22%3ERe%3A%20Removing%20owner%20from%20all%20OneDrives....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1263930%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F56139%22%20target%3D%22_blank%22%3E%40Jesper%20Stein%3C%2FA%3EIt%20seems%20you've%20solved%20this%20but%20there%20is%20a%20setting%20in%20ShareGate%20under%20Settings%20%26gt%3B%20Permissions%20%26amp%3B%20Notifications%20%26gt%3B%20Auto%20Assign%20as%20Administrator.%20It%20looks%20like%20a%20handy%20setting%20to%20turn%20off%20but%20it%20will%20add%20the%20user%20to%20all%20OneDrives%20within%20your%20tenancy.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20speaking%20to%20ShareGate%20support%20they%20sent%20me%20%3CA%20href%3D%22https%3A%2F%2Fsupport-desktop.sharegate.com%2Fhc%2Fen-us%2Farticles%2F115000647528-Can-I-remove-myself-as-an-administrator-after-I-have-auto-assigned-myself-as-one-%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20link%3C%2FA%3E%20which%20provides%20a%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted
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
Highlighted
Best Response confirmed by Jesper Stein (Contributor)
Highlighted

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

Highlighted

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

Highlighted

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

Thanks, 
Mario

Highlighted

Hi Jesper, what where the exact steps in ShareGate?

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

@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" 
Highlighted

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

Highlighted

@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

 

 

Highlighted

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

Highlighted

@Manidurai Mohanamariappan 

 

 

Thank you so Much! . It worked

Highlighted

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