Hi,
I'm trying to change the CN of multiple AD contacts in a csv from bt@gmail.com to bt@contoso.com
In the csv file contacts are listed like following:
bt@gmail.com
tb@gmail.com
...
Following is a working code for Users from the net. How do we do it for contacts?
Import-Module activedirectory$varCSV = "users.csv" $userlist = Import-Csv -Path $varCSV -Delimiter ","foreach ($user in $userlist){ $SamAccountName = $user.SamAccountName $FirstName = $user.GivenName $LastName = $user.Surname $DisplayName = $user.GivenName + " " + $user.Surname $UserPrincipalName = $user.UserPrincipalName + "@students.stdeclanscollege.ie" $JobTitle = $user.JobTitle $EmailAddress = $user.UserPrincipalName $Department = $user.Department $dn = (Get-ADUser -Identity $SamAccountName).DistinguishedName Get-ADUser -Identity $user.SamAccountName | Set-ADUser -DisplayName $DisplayName -GivenName $FirstName -Surname $LastName -Title $JobTitle -UserPrincipalName $UserPrincipalName -EmailAddress $UserPrincipalName -Department $Department Try { Rename-ADObject $dn -NewName $DisplayName } catch { Write-Output "Error Check Acc: " ($user.samaccountname) | Out-File C:\errors.txt -Append }}
TIA,
BT