how do I modify UPN using powershell setAdUser

rob m 256 Reputation points
2023-01-19T18:47:04.8233333+00:00

Hi I have a powershell script that creates a user un out AD TREE in the subdomain corp.xxx.ca, in the line below I modify the users AD profile to have a default HOME FOLDER H:

Set-ADUser -Identity $name -HomeDirectory \canopus\staff$name -HomeDrive H -Server corp.xxxxx.ca;

what I also would like to do is in the login username whiche defaults to

user@xxxx.ca -> user@corp.xxxx.ca as in the highlighted below upn

User's image

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,575 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jordi Rojas 266 Reputation points
    2023-01-19T18:57:42.9366667+00:00

    Hi,

    Here's a sample code to accomplish the task in Powershell:

    $LocalUsers = Get-ADUser -Filter {UserPrincipalName -like '*internal.local'} -Properties userPrincipalName -ResultSetSize $null
     
    $LocalUsers | foreach {$newUpn = $_.UserPrincipalName.Replace("internal.local","external.com"); $_ | Set-ADUser -UserPrincipalName $newUpn}
    

  2. Amit Singh 4,766 Reputation points
    2023-01-20T05:23:04.11+00:00

    #Get a list of the UPN suffixes

    Get-ADForest | Format-List UPNSuffixes

     #Let’s add the UPN suffix

    Get-ADForest | Set-ADForest -UPNSuffixes @{add="abc.xy"}

     #Get a list of the UPN suffixes

    Get-ADForest | Format-List UPNSuffixes

     #List of all the AD Users in the organization

    Get-ADUser -Filter * | Sort-Object Name | Format-Table Name, UserPrincipalName

     #Change the UPN for all the AD users in the organization

    $LocalUsers = Get-ADUser -Filter {UserPrincipalName -like '*abc.local'} -Properties UserPrincipalName -ResultSetSize $null

    $LocalUsers | foreach {$newUpn = $_.UserPrincipalName.Replace("abc.local","tomrocks.ch"); $_ | Set-ADUser -UserPrincipalName $newUpn}

     #Confirm that the UPN has been changed

    Get-ADUser -Filter * | Sort-Object Name | Format-Table Name, UserPrincipalName

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more