您好,登錄后才能下訂單哦!
最近公司收購新工廠需要大批量創建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.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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。