Set User Principal Name (UPN) via Powershell

In case you need to change the UPN in Active Directory for all the users in particular OU you can use the powershell command

For example, I want to change all user’s @xyz.com to @sysghost.com i will use the following command:

Get-ADUser -Filter * -SearchBase 'OU=XYZ,OU=USERS,DC=xyz,DC=com' -Properties userPrincipalName | foreach {Set-ADUser $_ -UserPrincipalName ("{0}@{1}" -f $_.name,"sysghost.com")}

To confirm if there are any users with UPN xyz.com i will use the following command in powershell:

Get-ADUser -Filter {UserPrincipalName -like "*@xyz.com"} | Select UserPrincipalName
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s