How to fetch a user's profile from Azure Active Directory using PowerShell

On my recent journey helping customers migrate from TFS to VSTS; one of the most common obstacle is verifying that users marked for active import to VSTS have matching AAD records. Thankfully there is a fairly streamlined way to do this using PowerShell and the Azure Graph API.

The magic is in the bellow PowerShell script. Feel free to copy and use it at your convenience.

#Author: Chev Bryan
#Company: Microsoft Corp.
#Date: Jan 01, 2018 00:00:01 EST

##First time running the script,
##ensure the AzureAD and MSOnline Modules are installed
#Install-Module AzureAD
#Install-Module MSOnline

#Connect to the MSOnline Service
#Please note: You must call the Connect-MsolService cmdlet before calling any other cmdlets.

#Fetch user by Principal Name (email address)
#Be sure to replace the with the email address of the user you wish to fetch
Get-MsolUser -UserPrincipalName

Please note, the first time you run this script, you may have to install the "AzureAD" and "MSOnline" Modules. To do that, simply un-comment the following lines from the code snippet above:

Install-Module AzureAD
Install-Module MSOnline

You can copy and run this script from PowerShell ISE, or save it and run it directly from the PowerShell command line.

Happy Scripting!