最近公司收购新工厂需要大批量创建AD账号,由于AD的自定义属性比较多需要添加proxyaddress邮件主SMP地址、直线经理Manager属性、extenstionAttribute4属性
创新互联专注于企业成都营销网站建设、网站重做改版、承德网站定制设计、自适应品牌网站建设、H5场景定制、商城网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为承德等各大城市提供网站开发制作服务。
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.cn
astest36ad 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.cn
astest37ad 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.cn
astest38ad 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.cn
PS 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 $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|#添加attribute自定义属性 -PassThrul后面可以用管道返回set-aduser命令
set-ADuser -add $custom
}
PS C:\Users\xxx>