Setting Ad object custom attributes

I am trying to update multiple extension attributes from a csv, before the update I cleared any values out. Does any one know a simpler solution?

 

Please see my existing script…

 

 

For example;

$users = Import-Csv $csvpath

ForEach ($user in $users)
{
$mailnickname = $.mailnickname
$new_en_displayname = $
.new_en_displayname
$new_smtp_proxyaddresses = $.new_smtp_proxyaddresses
$new_department = $
.new_department
$new_fr_Displayname = $.new_fr_Displayname
$new_en_smtp_address= $
.new_en_smtp_address.trim()

#######################################################################
 

 

If(IsData $mailnickname -eq “TRUE”){
$t=Get-ADObject -LDAPFilter “mailnickname=$mailnickname” -properties *
}
#if mailnickname exists then start!
if($t.mailnickname){
Write-Host “”
####################################################################################################################################################################################################################################################

#create error array
$error_array = @()

#remove all existing sharepoint attribute data b4 update with new values below if they have a value:
if($t.msExchExtensionCustomAttribute1){$t | Set-ADObject -remove @{msExchExtensionCustomAttribute1=$($t.msExchExtensionCustomAttribute1)} -verbose; write-host “$mailnickname - msExchExtensionCustomAttribute1 cleared”}
if($t.msExchExtensionCustomAttribute2){$t | Set-ADObject -remove @{msExchExtensionCustomAttribute2=$($t.msExchExtensionCustomAttribute2)} -verbose; write-host “$mailnickname - msExchExtensionCustomAttribute2 cleared”}

#############################################################################

set msExchExtensionCustomAttribute1 attribute with New French DisplayName!!
If(IsData $new_fr_Displayname -eq “TRUE”){
$error[0] = $null
$t | Set-ADObject -replace @{msExchExtensionCustomAttribute1 = $new_fr_Displayname} -verbose

$t | Set-ADObject -replace @{msExchExtensionCustomAttribute2 = $($t.displayname)} -verbose

$t | Set-ADObject -replace @{extensionattribute7 = $new_en_smtp_address} -verbose

$t | Set-ADObject -replace @{extensionattribute8 = $new_fr_smtp_address} -verbose

#############################################################################

 

 

 

 

you could better use gist to post your code here. That’ll make anyone to read and understand your code better.