If your tenant has multiple domains associated with it as many do, there may well be times you need to do some work with all users with a specific domain assigned as their UPN, for example updating their UPN or changing their email address (along with every other M365 option possible).
Here’s a very quick and easy PowerShell function that will get a list of users assigned to that domain. Simply run the function and specify the domain as a parameter – eg:
Get-UsersWithUPNDomain christurnbull.uk
would find all users in your tenant with @christurnbull.uk set in their UPN.
Function Get-UsersWithUPNDomain(){
param (
[Parameter(Mandatory=$true)][string]$domain
)
Get-MsolUser -All |? {$_.UserPrincipalName -like "*@$domain"}
}
Please note that as this function executes Get-MsolUser, you’ll obviously need to have installed the Msol module in PowerShell and connect to the Msol service before running this!

