通过脚本批量新建AD用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过脚本批量新建AD用户相关的知识,希望对你有一定的参考价值。

基本的创建AD用户的命令行,测试如下:

New-Aduser -Name "Test Account1" -Surname Test -Givenname Account1 -Company Contoso -Country CN -Department Test -City BJ -AccountPassword (ConvertTo-SecureString -AsPlainText "Ts12345678" -Force) -Path "OU=Users,DC=contoso,DC=com" -enabled $true -UserPrincipalname [email protected]

参考TechNet文档:
https://docs.microsoft.com/en-us/powershell/module/addsadministration/new-aduser?view=win10-ps

然后,设定参数,讲参数值从Excel表格传入:

$Users?=?Import-Csv?-Path?"C:Userlist-sn.csv"????????????
foreach?($User?in?$Users)????????????
{????????????
????$Displayname?=?$User.Firstname?+?" "?+?$User.Lastname????????????
????$UserFirstname?=?$User.Firstname????????????
????$UserLastname?=?$User.Lastname??????????????????????
????$UPN?=?$User.email??????????????????
????$Password?=?$User.Password??
$depart=$User.department

New-Aduser -Name $Displayname -Surname ?$UserLastname -Givenname $UserFirstname -Company Contoso -Country CN -Department $depart -City BJ -AccountPassword (ConvertTo-SecureString -AsPlainText "$Password" -Force) -Path "OU=Users,OU=$depart,DC=Contoso,DC=com" -enabled $true -UserPrincipalname $UPN????????????????
}

新建Excel文件,然后运行脚本,用户成功创建。

脚本参考文档:
https://social.technet.microsoft.com/wiki/contents/articles/24541.powershell-bulk-create-ad-users-from-csv-file.aspx#Reference

以上是关于通过脚本批量新建AD用户的主要内容,如果未能解决你的问题,请参考以下文章

如何在AD中批量创建域用户

AD账户userAccountControl属性值为544

批量修改AD用户的属性信息

如何在AD中批量创建域用户

linux批量新建用户帐号脚本

(转)通过shell脚本实现批量添加用户和设置随机密码以及生产环境如何批量添加