This minor task was part of a major activity I carried out for one of the clients recently here in Australia. Used the SharePoint PnP PowerShell to do this, pretty simple with the commands and controls it offers.
SharePoint PnP cmdlets reference – https://github.com/SharePoint/PnP-PowerShell
First and foremost, ensure you have installed the latest PnP module in your machine. Run this cmdlet to get the latest bits installed
Now verify the version by running this
Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
Firstly you must connect to SharePoint Online using Connect-PnPOnline cmdlet (none MFA environments)
$cred = Get-Credential Connect-PnPOnline -Url https://<tenant>-admin.sharepoint.com/ -Credentials $cred
If your Office 365 Environment is MFA enabled, use this instead (Notice the login is different to the traditional method)
Connect-PnPOnline -Url https://sitename-admin.sharepoint.com -UseWebLogin
Now we can run the Get-PnPUserProfileProperty cmdlet to get the information about the user’s profile and select only the PersonalUrl which is the URL of that user’s OneDrive for Business.
$username = "<UserName>" $OneDriveUrl = Get-PnPUserProfileProperty -Account $username | select PersonalUrl $OneDriveUrl
$username = "<UserName>" $OneDriveUrl = Get-PnPUserProfileProperty -Account $username | select PersonalUrl
There is it ! that’s the ultimate end user URL of OneDrive
One thought on “Get End User OneDrive URL with PowerShell”
Love this script. I’m just wondering how I could use this script on a list of users? So import-csv with a list of UPNs then run the script from this?