Forum Discussion

KrisSub2023's avatar
KrisSub2023
Brass Contributor
Jul 21, 2023

How do i get current OneDrive location from Multi Geo Tenat enviorment

Get-SPOUserOneDriveLocation -UserPrincipalName "email address removed for privacy reasons" gives location what exactly i need. How can i get the same by using PNP command? Please help.

 

I'm running a powershell script via Runbooks to get multi geo onedrive report. Hence getting the user onedrive location is important for me. I'm using pnp commands via client id and secret within my runbook.

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi KrisSub2023,

    To obtain the current OneDrive location of a user in a Multi-Geo tenant environment using PnP PowerShell, follow these steps:

    - Install the PnP PowerShell module in your environment (if not already installed) with the following command:

    Install-Module SharePointPnPPowerShellOnline -Force


    - Connect to SharePoint Online using PnP PowerShell and your client ID and secret. Ensure that your application has the required permissions in Azure AD.

    # Replace 'YourClientId', 'YourClientSecret', and 'https://your-tenant-admin.sharepoint.com' with your actual values
    $clientId = "YourClientId"
    $clientSecret = "YourClientSecret"
    $tenantAdminUrl = "https://your-tenant-admin.sharepoint.com"
    
    Connect-PnPOnline -Url $tenantAdminUrl -AppId $clientId -AppSecret $clientSecret


    - Retrieve the OneDrive location for the specific user:

    # Replace 'email address removed for privacy reasons' with the user's email address
    $userPrincipalName = "email address removed for privacy reasons"
    
    $onedriveLocation = Get-PnPTenantSite -User $userPrincipalName | Select -ExpandProperty OneDriveLocation


    -  The variable $onedriveLocation now contains the URL of the user's OneDrive location in the Multi-Geo tenant environment.

    - Once you have obtained the necessary information, don't forget to disconnect from SharePoint Online using the following command:

    Disconnect-PnPOnline

     

    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.


    If the post was useful in other ways, please consider giving it Like.


    Kindest regards,


    Leon Pavesic

    • KrisSub2023's avatar
      KrisSub2023
      Brass Contributor
      Looks User parameter is not available with this command. Please find the below error. Thanks for your response
      Get-PnPTenantSite : A parameter cannot be found that matches parameter name 'User'.
      • KrisSub2023 

         

        ChatGPT generated answer unfortunately, those can be abit hit and miss as it can invent variables that does't exist :xd:

        You can just run this: 

         

        Connect-SPOService -Url https://yourtentant-admin.sharepoint.com
        Get-SPOUserOneDriveLocation -UserPrincipalName "The UPN You want to checl"

         

Resources