-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathChange_Users_UPN.ps1
22 lines (16 loc) · 948 Bytes
/
Change_Users_UPN.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#The first two lines just set the location to the root of the C drive and clear the screen
Set-Location C:\
Clear-Host
#Get a list of the UPN suffixes
Get-ADForest | Format-List UPNSuffixes
#Let’s add the UPN suffix
Get-ADForest | Set-ADForest -UPNSuffixes @{add="tomrocks.ch"}
#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 '*tomrocks.local'} -Properties UserPrincipalName -ResultSetSize $null
$LocalUsers | ForEach-Object {$newUpn = $_.UserPrincipalName.Replace("tomrocks.local","tomrocks.ch"); $_ | Set-ADUser -UserPrincipalName $newUpn}
#Confirm that the UPN is changed
Get-ADUser -Filter * | Sort-Object Name | Format-Table Name, UserPrincipalName