In the previous blog post, I covered how to configure an additional User Principal Name for the ad.hypervlab.co.uk. Now we need to change the UPN for the 100 Users within the company so they can be synced with the Microsoft O365 Email Provision that the HypervLAB Company utilises.
# Import Powershell Modules
Import-Module -Name 'ActiveDirectory'
# Script Variables
$LocalUPN = (Get-ADForest).RootDomain
$FQDNUPN = (Get-ADForest).UPNSuffixes
$StagingOU = 'OU=TestOU,OU=User Accounts,OU=HypervLAB,DC=ad,DC=hypervlab,DC=co,DC=uk'
$QueryUser = Get-ADUser -Filter * -SearchBase $StagingOU
# Configure Users
ForEach ($User in $QueryUser) {
$NewUPN = "$($User.SamAccountName)" + "@" + "$FQDNUPN"
Get-ADUser $User | Set-ADUser -UserPrincipalName $NewUPN -Verbose
}