PowerShell Script To Update UPN in a domain

Hi again,

The other day a colleague ask me a quick way to update the UPN of a bunch of users in order to be ready to access to O365.

Firstly, and before running the below PowerShell, add the UPN that you are going to use (your verified domain in Office 365) to Active Directory Domains and Trusts. Then in a PowerShell console as an administrator, execute the following command:

$users = Get-ADUser -filter * -Server domain1.com -resultsetsize $null
foreach($user in $users)
{
$UPN = "$($user.sAMAccountName)@yourFederatedO365domain.com"
# Write-Host "Setting " $UPN
$user | Set-ADUser -UserPrincipalName $UPN
}

That’s all

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s