public/Change-UPN.ps1
function Change-UPN { [cmdletbinding(SupportsShouldProcess=$True)] param ( [string] [Parameter(Mandatory=$true)] $OldSuffix, [string] [Parameter(Mandatory=$true)] $NewSuffix ) Import-Module ActiveDirectory $OU = Choose-ADOrganizationalUnit -HideNewOUFeature | Select-Object DistinguishedName -ExpandProperty DistinguishedName $Users = Get-ADUser -Filter * -SearchBase $OU foreach ($U in $Users) { $NewUPN = $U.UserPrincipalName.Replace($OldSuffix,$NewSuffix) Set-ADUser -Identity $U.SamAccountName -UserPrincipalName $NewUPN } } |