I’ve got a .csv file formatted as shown below.
I want to take
UPN: lastf@domain.com
SAM: lastf
and update them to:
UPN: first.last@domain.com
SAM: first.last
CSV format for import
samaccountname,NewUserPrincipleName,NewSamAccountName
currentSamAccountName,newUPN@domain.com,newSamAccountName
I’ve already combined GivenName.SN@domain.com (UPN) and GivenName.SN (SAM) in the CSV file and have that ready for import.
My question is, will it work as written, or does it need to be two separate actions, first change the UPN, then change the SAM?
function Update-ADSamAccountName_UPN {
[CMDLETBINDING(SupportsPaging = $true,
SupportsShouldProcess = $true)]
param(
)
BEGIN {
} #end BEGIN
PROCESS {
Import-Csv c:\temp\Sam_UPN-Import.csv | ForEach-Object {Set-ADUser -Identity $_.samAccountName -Replace @{UserPrincipalName=$_.NewUserPrincipleName;SamAccountName=$_.NewSamAccountName}}
} #end PROCESS
END {
} #end END
} #end Update-ADSamAccountName_UPN