question

EavenHuang avatar image
0 Votes"
EavenHuang asked EavenHuang commented

Powershell New-Aduser to create new users with extensionAttributes

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered EavenHuang commented

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 "$Username@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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Ian,

I just tested it with my script and it works just perfect!!

Thanks a lot for your great reply, MOST PROFESSIONAL!!!

0 Votes 0 ·