Get OneDrive Site URLs for Users Using PowerShell
Do you need to compile a list of all your organization’s OneDrive site URLs for users? This can be increasing OneDrive storage, streamlining administrative tasks, managing permissions, or facilitating user migration projects.. Fear not, this blog will equip you with several methods to retrieve the list of OneDrive URLs for users in the organization. Whether you’re dealing with a single user in distress or need to access a comprehensive list of URLs, we’ve got you covered!
Firstly, let’s understand the format of OneDrive URLs. A user’s OneDrive URL typically follows the format: https://<tenant name>-my.sharepoint.com/personal/<user principal name>
If you visit OneDrive web currently, you will see the URL formatted like this: https://<tenant name>my.sharepoint.com/personal/alias/_layouts/15/onedrive.aspx?view=1
Now, Microsoft is shortening OneDrive for Business web URLs to simplify navigation. The rollout will begin in mid-June 2024 and is expected to be completed by mid-July 2024.
The new URLs of OneDrive web will have: https://<tenant name>-my.sharepoint.com
This change applies not only to the main OneDrive view but also to specific sections like Home, My Files, and Favorites.
Note: This is a seamless change. You’ll still be able to access files, share links, and browse other users’ OneDrive just as before. Existing links, bookmarks, and automated processes will continue to work flawlessly.
To get the list of OneDrive for Business URLs for all users, sign-in to Microsoft 365 admin center with your SharePoint administrator, global reader, or reports reader account.
- Navigate to Reports –> Usage –> OneDrive Usage Report
- Click on Usage next to ‘Activity’ slider.
- Export the table as a CSV file for easier searching and copying.
If you see GUIDs instead of URLs, go to the Reports setting and clear the “Display concealed user, group…” checkbox. By doing so, identifiable names in Microsoft 365 usage reports will be displayed.
Note: If the Site URL is missing in OneDrive usage report, you may need to be patient. Microsoft is aware of the issue and is working on a resolution. However, due to the operation’s complexity, they indicated that it may take a long time to fix.
To get the OneDrive site URLs for users using PowerShell, find the methods mentioned below.
- Get OneDrive site URLs and size report using PowerShell script
- Get OneDrive URL for specific user using PnP PowerShell
- Get OneDrive URL for specific user using MS Graph PowerShell
To bypass the waiting time and need for manual navigation, we have developed a user-friendly script to export OneDrive site URLs and size report. This script simplifies the process, saving you time and effort.
Make sure to connect to the latest SharePoint Online Management PowerShell before running the script.
Download Script: GetOneDriveSiteURLs.ps1
Script Highlights:
- The script fetches the OneDrive URLs and storage usage.
- Exports report results into CSV format for easy access and analysis.
- The script is scheduler friendly. I.e., You can pass the credential as parameters instead of saving inside the script.
Script Execution:
To run this script, you can choose any one of the methods below.
Method 1: Execute the script with MFA/non-MFA accounts.
./GetOneDriveSiteUrls.ps1
Upon execution, you will be prompted to enter your SharePoint organization name. Once provided, the script will download the OneDrive site URLs for the specified tenant.
Method 2: Execute the script by explicitly mentioning credentials.
./GetOneDriveSiteUrls.ps1 -UserName [email protected] -Password XXX
Also, you can use the above format to run a PowerShell script from Task Scheduler. If the admin account has MFA, then you need to disable MFA based on the Conditional Access policy.
Sample Output:
The exported report contains the following attributes:
- OneDrive Url
- Owner UPN
- Storage Used Size (MB)
- Storage Quota (MB)
- Last Content Modified Date
Note – When you change the ownership of a specific site, the new owner’s name will be displayed as the Owner UPN. In such cases, the site name and the owner’s name will not match.
Here’s an example of sample output.
SharePoint Patterns and Practices (PnP) PowerShell is a set of cmdlets designed to automate and simplify common SharePoint and OneDrive tasks. Before proceeding further, connect to SharePoint Online Using PnP PowerShell.
Run the following cmdlet to retrieve the OneDrive site URL for specific user.
Get-PnPUserProfileProperty -Account [email protected] | Select-Object -ExpandProperty PersonalUrl
The above code will fetch Harvey’s OneDrive site URL.
By understanding the different methods outlined in this blog post, you can efficiently retrieve OneDrive URLs for your users in a SharePoint environment. This empowers you to manage user access, troubleshoot issues, and ensure accurate access to cloud storage.
You can also use Microsoft Graph PowerShell to access OneDrive and other Microsoft 365 services. Firstly connect to Microsoft Graph PowerShell with “Directory.ReadWrite.All”, “Sites.ReadWrite.All”, “Files.ReadWrite.All” permission scope to retrieve OneDrive URL for a Microsoft 365 user.
Then, execute the following code to get the OneDrive URL for a specific user.
$userPrincipalName = "[email protected]" $userObject = Get-MgUser -Filter "userPrincipalName eq '$userPrincipalName'" $userOneDrive = Get-MgUserDefaultDrive -UserId $userObject.id $oneDriveWebUrl = $userOneDrive.webUrl Write-Host "OneDrive WebURL for ${userPrincipalName}: $oneDriveWebUrl"
In the provided script, you should replace the placeholder email address “[email protected]” with the actual user principal name (email address) of the user whose OneDrive URL you want to retrieve.
To gain OneDrive URL for specified set of users, run the following.
$users = @("[email protected]", "[email protected]", "[email protected]") foreach ($user in $users) { $userPrincipalName = $user $userObject = Get-MgUser -Filter "userPrincipalName eq '$userPrincipalName'" if ($userObject) { $userOneDrive = Get-MgUserDefaultDrive -UserId $userObject.id $oneDriveWebUrl = $userOneDrive.webUrl Write-Host "OneDrive WebURL for ${userPrincipalName}: $oneDriveWebUrl" } else { Write-Host "User not found: $userPrincipalName" } }
The best method depends on your needs and technical expertise:
- The OneDrive Usage Report is a user-friendly option for a quick overview.
- The PowerShell script is ideal for creating a comprehensive list of all OneDrive URLs.
- PnP PowerShell and Microsoft Graph PowerShell are suited for advanced users comfortable with scripting and programmatic access.
By leveraging these methods, you can efficiently manage OneDrive URLs within your organization, ensuring smooth user access and data management!