Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Add SMTP, Manager and extensionAttribute4 attributes to create AD accounts in batch

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Recently, the company needs to create a large number of AD accounts for the acquisition of new factories. Due to the large number of custom attributes of AD, it is necessary to add proxyaddress mail main SMP address, line manager Manager attribute and extenstionAttribute4 attribute.

Userid UPN Initials Fistname Lastname DisplayName Office telephoneNumber postalcode fax Email StreetAddress City Province country company C mobile Title Department Manager SMTP

Astest35ad test35.xx.ad@test.cn xx test35 AD test35ad 506F test xx xxxx test35.xx.ad@test.cn No. 55, Persiaran Selangor, Seksyen 49 GZ GD China Guangzhou XX Co., Ltd. Cn test test xx linemanagerAD SMTP:test35.xx.ad@test.cn

Astest36ad test36.xx.ad@test.cn xx test36 AD test36ad 507F test xx xxxx test36.xx.ad@test.cn No. 55, Persiaran Selangor, Seksyen 50 GZ GD China Guangzhou XX Co., Ltd. Cn test test xx linemanagerAD SMTP:test36.xx.ad@test.cn

Astest37ad test37.xx.ad@test.cn xx test37 AD test37ad 508F test xx xxxx test37.xx.ad@test.cn No. 55, Persiaran Selangor, Seksyen 51 GZ GD China Guangzhou XX Co., Ltd. Cn test test xx linemanagerAD SMTP:test37.xx.ad@test.cn

Astest38ad test38.xx.ad@test.cn xx test38 AD test38ad 509F test xx xxxx test38.xx.ad@test.cn No. 55, Persiaran Selangor, Seksyen 52 GZ GD China Guangzhou XX Co., Ltd. Cn test test xx linemanagerAD SMTP:test38.xx.ad@test.cn

The PS1 code is as follows:

PS C:\ Users\ xxx > $imports = Import-Csv-path'C:\ Users\ xxx\ Documents\ Windows Server\ Power Shell\

Bach AD PS\ BulkAD_Final.csv' # Import CSV form

PS C:\ Users\ xxx > foreach ($import in $imports) {

$Path = "OU=xx5F,OU=xxx,OU=UserAcc,DC=CBACorp,DC=xxx,DC=asia" $Password = "xxxX123" # change your password $enabled = $True $changePW = $False # cancel UserMustChangePasswordAtNextLogon,False cancel Ture check $sam = $import.userid $upn = $import.upn $ini = $import.Initials $givenname = $import.fistname $surname = $import.lastname $displayname = $import.displayname $OfficeName = $import.office $telephoneNumber = $import.TelephoneNumber $email = $import.email $StreetAddress = $import.StreetAddress $L = $import.city $st = $import.province $co = $import.country $c = $import.c $mobile = $import.mobile $title = $import.title $department = $import.department $Company = $import.Company

# get the member OU object of the manager column of the table

$Manager = Get-ADUser-Identity $import.manager-Properties * | Select-Object DistinguishedName

$employeeID = $import.employeeID

$name = $givenname + "" + $ini + "" + $surname

$postalCode = $import.postalCode

$fax = $import.fax

# define custom attributes

$custom = @ {} # create an empty hash table

$custom.proxyAddresses = $import.SMTP # assign values to custom attributes

$custom.extensionAttribute4 = 'xxx' # assign values to custom attributes

New-ADUser-name $name-SamAccountName $sam-UserPrincipalName $upn-DisplayName $displayname-GivenName $given

Name-SurName $surname-Initials $ini-Office $OfficeName-OfficePhone $telephoneNumber-EmailAddress $email-StreetAddr

Ess $StreetAddress-City $L-State $st-Country $c-MobilePhone $mobile-Title $title-Department $department-Company $

Company-EmployeeNumber $employeeID-postalCode $postalCode-fax $fax-Path $path-AccountPassword (ConvertTo-SecureStri

Ng $password-AsPlainText-force)-Enabled $enabled-ChangePasswordAtLogon $changePW-manager $manager-PassThru |

# add attribute custom attributes-PassThrul can be followed by piping to return the set-aduser command

Set-ADuser-add $custom

}

PS C:\ Users\ xxx >

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report