Powershell: Set AD User Principal Name (UPN) to match with Primary SMTP Email Address

I have created a PS module which i am sharing with you for changing the User Principal Name (UPN) of a user in Active Directory to their Primary SMTP Address. The Module will change the UPN of a user to match with their Primary SMTP Email ID. *******

There are three functions exported from the module Set-UPNtoPSMTPv1 which are shown in below screenshot. To import the module you have to download the module and save it in a folder and use Import-Module <module path with filename> in your Powershell Session. e.g. Import-Module c:\temp\Set-UPNtoPSMTPv1.psm1

Please make sure ActiveDirectory Powershell Module is Imported on the machine before running the Module and make sure you have required edit permissions in active directory.

PS> Import-Module ActiveDirectory

PS>  Import-Module c:\temp\Set-UPNtoPSMTPv1.psm1

PS> Get-command -module Set-UPNtoPSMTPv1

Once the Module is imported. You can use below commands on the Powershell console session to execute these functions.

PS> Set-UPNtoPSMTPOneUser <userprincipalname>

PS> Set-UPNtoPSMTPListofUsers <Text File Path Containing UPNs>

PS> Get-UPNlist

OR

PS> “userprincipalname” | Set-UPNtoPSMTPOneUser

PS>”<UPN file path>” | Set-UPNtoPSMTPListofUsers

I have created Help information for each function with examples which you can access using below commands:

***HELP INFORMATION / DOCUMENTATION***

PS> get-help Set-UPNtoPSMTPOneUser

PS> get-help Set-UPNtoPSMTPOneUser -examples

PS> Get-help Set-UPNtoPSMTPListofUsers

PS> Get-help Set-UPNtoPSMTPListofUsers -examples

PS> Get-help Get-UPNlist

*********************

The Script can be downloaded from Microsoft TechNet Gallery : Set-UPNtoPSMTPv1

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

error: