Find a user’s OneDrive for Business site URL with PowerShell
While working on an offboarding script, one of the requirements was to send an e-mail to the manager with the OneDrive for Business URL of the user that was going to get disabled. There is quite some information on the internet on how to get this with CSOM, but not a lot in how to get it with PowerShell for IT Pros like me … we prefer PowerShell cmdlets to code! While this is not available in the default SharePoint Online Module ,we can use the PnP PowerShell cmdlets to do it!
The first thing you must do is to get your credential and use the Connect-PnPOnline cmdlet to connect to your SharePoint Online Admin Center!
$cred = Get-Credential
Connect-PnPOnline -Url https://<tenant>-admin.sharepoint.com/ -Credentials $cred
You can then 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
That’s it! Once you know the right cmdlets to use, it’s that simple!
|Leave a comment and don’t forget to like the Vlad Talks Tech Page on Facebook and to follow me on Twitter here for the latest news and technical articles on SharePoint. I am also a Pluralsight author, and you can view all the courses I created on my author page.