How to Gain Owner Access to OneDrive for Business Sites in Office 365?

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.

Access Any User's OneDrive site as Global Administrator:
If you have "Global Administrator" rights, follow these steps to access OneDrive for any user in the tenant:
  1. Login to Microsoft Admin portal at https://admin.microsoft.com/,
  2. Expand Users >> Active Users >> Search and find the user to get OneDrive site access.
  3. 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.
    access another users onedrive site
What if you have only "SharePoint Admin" rights but not global administrator?

How to get admin access to the OneDrive for Business site in Office 365?
How to grant access to OneDrive for business to another user? To gain access to a user's OneDrive site, follow these steps:
  • Login to SharePoint Online Admin Center
  • Click on "User Profiles" link from left navigation >> Click on "Manage User Profiles" link under "People" group
    change onedrive site collection administrator
  • Search and pick the user profile which you want to gain access. From the search result, Click on the menu item "Manage site collection owners" from the context menu.
    Add administrator to onedrive for business in office 365
  • By default, The owner of the OneDrive site collection is listed as the Primary Site Collection Administrator and in Site Collection Administrators. (You can have only one  primary site collection Admin!). Add any additional administrators to the site collection in "Site Collection Administrators" field. You can change the primary site collection administrator as well to remove the owner from onedrive for business site.
    change site collection administrator for onedrive site collection
  • Click on "OK" to commit your changes!
Now, you can gain access to all files and folders for the particular user. Instead of manually doing these steps to gain access to OneDrive site, you can use PowerShell script to add administrator permissions to OneDrive for business sites.

PowerShell to Add Site Collection Administrator to OneDrive for Business Site Collection:
If you need to access another user's OneDrive for Business site, you'll need to either change the site collection owner or add additional administrators to the site collection. Use this PowerShell script on SharePoint Online Management Shell to add an administrator to OneDrive for business.
#Set Runtime Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$OneDriveSiteUrl="https://crescent-my.sharepoint.com/personal/biadmin_crescent_com"
$SiteCollAdmin="[email protected]"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –credential $Cred

#Add Site Collection Admin to the OneDrive
Set-SPOUser -Site $OneDriveSiteUrl -LoginName $SiteCollAdmin -IsSiteCollectionAdmin $True
Write-Host "Site Collection Admin Added Successfully!"
This PowerShell grants access to OneDrive for business to another user.

Add Site Collection Admin to All OneDrive for Business Site Collections
As there is no direct user interface to do add site collection administrator to OneDrive for Business sites, Here is the PowerShell script you can utilize to add additional administrators in bulk.
#Set Runtime Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteCollAdmin="[email protected]"

#Get Credentials to connect to the SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –credential $Cred

#Get all OneDrive for Business Site collections
$OneDriveSites = Get-SPOSite -Template "SPSPERS" -Limit ALL -IncludePersonalSite $True
Write-Host -f Yellow "Total Number of OneDrive Sites Found: "$OneDriveSites.count

#Add Site Collection Admin to each OneDrive
Foreach($Site in $OneDriveSites)
{
    Write-Host -f Yellow "Adding Site Collection Admin to: "$Site.URL 
    Set-SPOUser -Site $Site.Url -LoginName $SiteCollAdmin -IsSiteCollectionAdmin $True
}
Write-Host "Site Collection Admin Added to All OneDrive Sites Successfully!" -f Green
This script adds site collection admin to all OneDrive for Business site collections. By adding a user as a site owner or site collection administrator, you are granting full access to all the files and folders in the site. How about adding a new admin to all existing sites where a particular user was a site owner?
#Parameters
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$OldAdminID = "[email protected]"
$NewAdminID = "[email protected]"

#Connect to SharePoint Admin Center
Connect-SPOService -url $TenantAdminURL

#Get All Sites where a particular user is owner
$Sites  =  Get-SPOSite -IncludePersonalSite $true -Limit All | Where {$_.Owner -eq $OldAdminID}

#Add NewAdmin as Site Collection Owner to all sites
$Sites | ForEach-Object { 
    #Set-SPOUser -Site $_.Url -LoginName $NewAdminID -IsSiteCollectionAdmin $True
    Write-host "Added Site collection Admin to" $_.URL
}

PnP PowerShell to Add Site Collection Admin to OneDrive Site
Here is how to add OneDrive for Business site collection administrator with PowerShell:
#Set Runtime Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$OneDriveSiteUrl="https://crescent-my.sharepoint.com/personal/sjackson_crescent_com"
$SiteCollAdmin="[email protected]"
 
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -UseWebLogin

#Add Site collection Admin
Set-PnPTenantSite -Url $OneDriveSiteUrl -Owners $SiteCollAdmin
Similarly, You can add a site collection administrator to all OneDrive for business sites as:
#Set Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteCollAdmin="[email protected]"
 
#Connect to PnP Online to the Tenant Admin Site
Connect-PnPOnline -Url $AdminSiteURL -UseWebLogin
 
#Get All OneDrive Sites
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"

#Loop through each site
ForEach($Site in $OneDriveSites)
{ 
    #Add Site collection Admin
    Set-PnPTenantSite -Url $Site.URL -Owners $SiteCollAdmin
    Write-Host -f Green "Added Site Collection Admin to: "$Site.URL
}
This PowerShell script only Adds given user as additional site collection administrators. Existing administrators will stay!
To remove OneDrive Site collection Admin, use: How to Remove Site Collection Administrator from OneDrive?

2 comments:

  1. How do I add O365 Group as secondary admin? The O365 group shows as " member" in sharepoint GUI...

    ReplyDelete
    Replies
    1. There is no "Secondary Admin" in SharePoint Online! You can add Site collection Administrators to SharePoint Online site through PowerShell as in: How to Add Site Collection Administrator in SharePoint Online?

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.