Get the App
SLTechnology News&Howtos  ›  Servers  › 

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

Shulou Source: shulou.com Published: 2022-06-02 12:45:08 10月02日 Update

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 >

Tags: Attributes forms accounts codes companies commands addresses bulk passwords objects factories members lines pipes managers mail hashes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Redmi macOS OPPO Reno