Is there a powersheel script to get a list of all OneDrive for business site/storage where a particular person is site collector admin?

Aman Akhauri 1 Reputation point
2022-11-22T08:57:22.34+00:00

I want to get a list of all the OneDrive/sharepoint site location where ******@def.com is site collector admin.

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | OneDrive | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Jinwei Li-MSFT 4,736 Reputation points Microsoft External Staff
    2022-11-29T02:30:34.427+00:00

    Hi @Anonymous ,

    Please follow the steps:

    1. Grant Admin Access to All OneDrive for Business Site Collections.
        #Set Runtime Parameters  
        $AdminSiteURL="https://tenant-admin.sharepoint.com"  
        #Global Admin  
        $SiteCollAdmin="******@tenant.onmicrosoft.com"  
        #Connect to SharePoint Online Admin Center  
        Connect-SPOService -Url $AdminSiteURL -credential (Get-Credential)  
         #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  
      
    2. Please run the below PowerShell script to get a particular person site collection.
       #Set Config Parameters  
       $AdminSiteURL="https://crescent-admin.sharepoint.com"  
       $UserAccount="******@crescent.com"  
      
       Try {  
           #Setup Credentials to connect  
           $Cred= Get-Credential  
      
           #Setup the context  
           $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)  
           $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
      
           #Get the User  
           $User = $Ctx.web.EnsureUser($UserAccount)  
           $Ctx.Load($User)  
           $Ctx.ExecuteQuery()  
      
           #Get OneDrive Site URL from User Profile  
           $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Ctx)  
           $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)  
           $Ctx.Load($UserProfile)  
           $Ctx.ExecuteQuery()  
      
           #Get the User Profile Property  
           Write-host $UserProfile.PersonalUrl  
      
       }  
       Catch {  
           write-host -f Red "Error Getting User Profile Properties!" $_.Exception.Message  
       }  
      

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.