本文共 3143 字,大约阅读时间需要 10 分钟。
最近公司收购新工厂需要大批量创建AD账号,由于AD的自定义属性比较多需要添加proxyaddress邮件主SMP地址、直线经理Manager属性、extenstionAttribute4属性
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 test35 ad 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.cnastest36ad test36.xx.ad@test.cn xx test36 AD test36 ad 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.cnastest37ad test37.xx.ad@test.cn xx test37 AD test37 ad 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.cnastest38ad test38.xx.ad@test.cn xx test38 AD test38 ad 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.cnPS C:\Users\xxx> $imports = Import-Csv -path 'C:\Users\xxx\Documents\Windows Server\Power Shell\
Bach AD PS\BulkAD_Final.csv' #导入CSV表格PS C:\Users\xxx> foreach ($import in $imports) {$Path = "OU=xx5F,OU=xxx,OU=UserAcc,DC=CBACorp,DC=xxx,DC=asia" $Password = "xxxX123" #自行修改密码 $enabled = $True $changePW = $False #取消UserMustChangePasswordAtNextLogon,False取消,Ture勾选 $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#获取表格manager列的成员OU对象
$Manager = Get-ADUser -Identity $import.manager -Properties * |Select-Object DistinguishedName$employeeID = $import.employeeID$name = $givenname + " " + $ini + " " + $surname$postalCode = $import.postalCode$fax = $import.fax#定义自定义属性$custom = @{} #创建空的哈希表$custom.proxyAddresses = $import.SMTP #给自定义属性赋值$custom.extensionAttribute4 = 'xxx' #给自定义属性赋值New-ADUser -name $name -SamAccountName $sam -UserPrincipalName $upn -DisplayName $displayname -GivenName $givenname -SurName $surname -Initials $ini -Office $OfficeName -OfficePhone $telephoneNumber -EmailAddress $email -StreetAddress $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-SecureString $password -AsPlainText -force) -Enabled $enabled -ChangePasswordAtLogon $changePW -manager $manager -PassThru|#添加attribute自定义属性 -PassThrul后面可以用管道返回set-aduser命令
set-ADuser -add $custom}PS C:\Users\xxx>
转载于:https://blog.51cto.com/13756650/2372925