Using customattributes

I have a simple user creation script that works great except for extensionattributes. I’m having issues with the autopopulate/translation of the extenstion attributes. I’m familiar with set-aduser and the process of adding extension attributes but with New-aduser it needs “-otherattributes” to define the custom attribute. Which works fine if I manually add it, but wont work in my translation.(or I can’t get the syntax correct) How do I properly incorporate the ability to pull custom/extension attributes straight from the csv?

import-csv “.\newusers.csv” | Select-Object Title, Department, City, State, Office, EmployeeID,DBRMember,Manager?,Contractor,VIP,`
@{name=‘name’;e={($.‘First Name’+’ '+$.‘Last Name’)}},
@{name=‘samaccountname’;e={($.‘First Name’.substring(0,1)+$.‘Last Name’).tolower()}},
@{name=‘UserPrincipalName’;e={($.‘First Name’.substring(0,1)+$.‘Last Name’).toLower()+“”}},
@{name=‘displayname’;e={$.‘First Name’+’ '+$.‘Last Name’}},
@{name=‘givenname’;e={$.‘First Name’}},
.‘Last Name’}},

For example, this works when manually specified

New-Aduser -ChangePasswordAtLogon $true -Enabled $true -AccountPassword $(ConvertTo-Securestring ‘P@$$word’ -AsPlainText -force)`
-Description "Test User Creation By Script"`
-HomeDrive ‘h:’ `
-HomeDirectory "\company\dfs\users%username%"`
-Company “Company, Inc” `
-StreetAddress “1234 Innovation Way” `
-PostalCode "12345"`
#-OtherAttributes @{extensionAttribute1=“TEST”;extensionAttribute2= “TEST2”; extensionattribute3=“Test3”; extensionattribute4=“Test4”}

Build a hashtable from your CSV columns and pass that as the value to the OtherAttributes parameter. Tested on 2012 R2:

#Sample CSV saved as csv1

$users = Import-Csv c:\csv1.csv

foreach ($user in $users) {

    $sa = $user.sAMAccountName
    $oa = @{
       adminDescription = $user.attr1
       adminDisplayName = $user.attr2

    New-ADUser -Name $sa -OtherAttributes $oa