Powershell New-Aduser to create new users with extensionAttributes

Eaven HUANG 2,191 Reputation points
2021-07-21T08:54:32.197+00:00

Dear friends,

I'm working on a PowerShell script, trying to create new users in batch from .csv file, where we also have extensionAttributes1 and extensionAttributes2 included. I tested the script from our testing environment and it works well without extensionAttributes. The extensionAttributes are integrated from Exchange setup.exe.

Any idea how we can configure the extensionAttributes into our script so when new users were created, these extensionAttributes will be set together? I tried to define -OtherAttributes but didn't know how to get this work with my script.

Any help is really appreciated!

$ADUsers = Import-csv C:\testing\test01.csv

foreach ($User in $ADUsers)
{
$Lastname = $User.EnglishLastName
$Firstname = $User.EnglishFirstName
$department = $User.Department
...
New-ADUser -SamAccountName $Username
-UserPrincipalName "$Username@test .edu.cn" `
-Name "$Firstname $Lastname"

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-07-21T10:19:34.47+00:00

    Hi,

    You can use the "OtherAttributes" parameter to set attributes not represented by parameters.

    $ADUsers = Import-csv C:\testing\test01.csv

    foreach ($User in $ADUsers)  
    {  
    $Lastname = $User.EnglishLastName  
    $Firstname = $User.EnglishFirstName  
    $department = $User.Department  
    ...  
    New-ADUser -SamAccountName $Username -UserPrincipalName "$******@test.edu.cn" -Name "$Firstname $Lastname" `  
        -OtherAttributes @{'extensionAttribute1'=$User.extensionAttribute1;'extensionAttribute2'=$User.extensionAttribute1}  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.