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

Brass Contributor

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.

6 Replies

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

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"

 

I know about this. but is there any way to get from pnp commands ?
Unfortunatly there's no PnP command for this as of yet 😞

But SPO module works in runbook so just install this one and then run it:
https://www.powershellgallery.com/packages/Microsoft.Online.SharePoint.PowerShell/16.0.21411.12000
Can you help how can i use Connect-SPOService with in my runbook ? i can't save the credentials within the automation account as per policy . what is the approach for other type of authentication ?