Multiple UPNs apply to multiple groups of users

To start with I need to create the UPNS in AD and then exported a list of users

Get-Mailbox -ResultSize Unlimited |Select-Object UserPrincipalName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-CSV c:\temp\exportsmtpUserPrincipalName.csv -NoTypeInformation

Once I had my list of users in different txt documents I can run the below PowerShell script to change the UPN’s

Import-Module ActiveDirectory

$oldSuffix = “abc.local”
$newSuffix = “”

Get-Content “C:\files\users.txt” | Get-ADUser | ForEach-Object {
$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -UserPrincipalName $newUpn

The following two tabs change content below.

Huseyin Kartal

Latest posts by Huseyin Kartal (see all)

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir


This site uses Akismet to reduce spam. Learn how your comment data is processed.