Prepopulate domain field
Hive HKEY_LOCAL_MACHINE
Key path SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon
Value name DefaultDomainName
Value type REG_SZ
Value Data yourdomain.com
Prepopulate domain field
Hive HKEY_LOCAL_MACHINE
Key path SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon
Value name DefaultDomainName
Value type REG_SZ
Value Data yourdomain.com
Most of the time, you see the “Access Denied. You do not have permissions to call this cmdlet” error message because of a non-existent UPN name in the “-UserPrincipalName” parameter.
To verify this, you can combine Get-MsolUser and Set-MsolUserPrincipalName cmdlets to include this validation check to get some more meaningful error message.
I suggest you replace “Set-MsolUserPrincipalName -UserPrincipalName $365 -NewUserPrincipalName $email”
with “Get-MsolUser -UserPrincipalName $365 | Set-MsolUserPrincipalName -NewUserPrincipalName $email” and let us know the outcome.