user1387493
user1387493

Reputation: 21

How to populate other attributes when using powershell 2.0 new-aduser?

When trying to create users from a file I get an error when -otherAttributes @{} is added to ps script. I am new to powershell and can not get it to work. Any guidance is appreciated. This is My code:

Import-Module ActiveDirectory
$OU = 'ou=Staging OU, dc=Domain, dc=net'
$usrfile = "\\servername\testuser.csv"

Import-Csv $usrfile | 
ForEach-Object {
     New-ADUser -SamAccountName $_.samaccountname -UserPrincipalName $_.Userprincipalname -Name $_.Name -DisplayName $_.displayname -GivenName $_.givenname -Surname $_.sn -Initials $_.initials -Title $_.title -OtherName $_.middlename `
-Description $_.description -Department $_.department -EmployeeID $_.employeeid -Path $OU -Country $_.c `
-OtherAttributes @{departmentNumber=$user.departmentnumber;localeID=$user.localid;extensionAttribute1=$user.extensionAttribute1;employeeType=$user.employeetype} `
-AccountPassword (ConvertTo-SecureString "Password" -AsPlainText -Force) -Enabled $true `
-PasswordNeverExpires $false -ChangePasswordAtLogon $true -PassThru 
    } > Import.log

Upvotes: 2

Views: 15626

Answers (3)

José Ibañez
José Ibañez

Reputation: 712

The parameter "-otherAttributes @{}" fails in my AD. I found other way change this value in AD.

Try with this:

PS> Set-ADuser -identity joseiba -Clear 'msRTCSIP-PrimaryUserAddress'
PS> Set-ADuser -identity joseiba -Add @{'msRTCSIP-PrimaryUserAddress'='[email protected]'}

BR

Upvotes: 2

tallyn
tallyn

Reputation: 1

you left out your ' around the ldapdisplayname for the otherattributes

@{departmentNumber=$user.departmentnumber; should be: @{'departmentNumber'=$user.departmentnumber;

you need the ' around each ldapdisplayname in otherattributes.. just fought this myself dealing with the notes field

Upvotes: 0

Brian Desmond
Brian Desmond

Reputation: 4503

Make sure you have all your $'s as $_... when accessing the object in the current loop iteration. I see some aren't.

Upvotes: 0

Related Questions