基本的创建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 testaccount1@contoso.com
参考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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。