network technician/administrator/manager blog
OneDrive Site Collection Administrators
OneDrive Site Collection Administrators

OneDrive Site Collection Administrators

By default, When SharePoint My Site or OneDrive site collection is created by the user, SharePoint assigns primary site collection administrator rights to the user. In some cases, you may need to access another user’s OneDrive for Business site. E.g. User left the company and the manager of the user wants to gain access, Backup purposes, compliance, security, etc.

Option One

Login to Microsoft Admin portal at https://admin.microsoft.com/,

Expand Users >> Active Users >> Search and find the user to get OneDrive site access.

Click on the user name to open the property pane >> Click on “OneDrive” tab and then Click on “Create link to files” link. This creates link to the OneDrive site of the user and adds you as site collection administrator to that site.

Option Two

If its one single user your needing to edit, the simplest would be to open SharePoint admin center.

Go to your SharePoint admin center, click on user profiles and search for the user in question. From there you will get several options, to edit who can access the accounts OneDrive you want to click Manage site collection owners.

Then simple remove or even add a user to be an admin of this users OneDrive.

Option Three

To remove a user on mass from your O365 tenancy would be PowerShell.

First install the pre-requisite module.

Install-Module -Name Microsoft.Online.SharePoint.PowerShell -RequiredVersion 16.0.8029.0

Once installed copy the below code into notepad and save as OneDriveAdminRemoval.ps1

You will need to update the code to work with your environment. Simply change the $AdminCenterURL and the $SearchAccount you’re looking to remove.

#Parameters
$AdminCenterURL = "https://******-admin.sharepoint.com"
$SearchAccount = "*******@*********.com"
 

    #Connect to SharePoint Online Admin Center
    Connect-SPOService -Url $AdminCenterURL
 
    #Get All OneDrive for Business Sites in the Tenant
    $OneDriveSites = Get-SPOSite -Limit ALL -includepersonalsite $True -Filter "Url -like '-my.sharepoint.com/personal/'"
      
    #Loop through each OneDrive Site
    Foreach($Site in $OneDriveSites)
    {
        Write-host "Scanning site:"$Site.Url -f Yellow
 
        #Get All Site Collection Administrators
        $SiteAdmins = Get-SPOUser -Site $Site.Url | Where {$_.IsSiteAdmin -eq $true}
 
        #Iterate through each admin
        Foreach($Admin in $SiteAdmins)
        {
            #Check if the Admin Name matches
            If($Admin.LoginName -eq $SearchAccount)
            {
                #Remove Site collection Administrator           
                Set-SPOUser -site $Site -LoginName $AdminAccount -IsSiteCollectionAdmin $False | Out-Null
                Write-host "`Removed Site Collection Admin from:"$Site.URL -f Green
            }
        }
    }

The script when run will ask you to login to your tenancy, please use your tenant admin account.

Now it will search for your OneDrive accounts and check for the existence of the account you are looking for, if found, will remove and the output will turn green.