- Make sure that the user@example.com is a valid Entra ID user account
- Stop using the MSOnline module (it's deprecated). Use MSGraph instead.
# Connect to Microsoft Graph
Connect-MgGraph
# Get user by User Principal Name (UPN)
$user = Get-MgUser -UserPrincipalName "user@example.com"
This will retrieve the user object based on the specified UPN from Microsoft Graph. Make sure to have the Microsoft Graph PowerShell module installed (Install-Module -Name Microsoft.Graph
). The Connect-MgGraph
cmdlet is used to establish a connection to Microsoft Graph before executing other Graph-related cmdlets.
hth
Marcin