Powershell批量新建AD域账号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powershell批量新建AD域账号相关的知识,希望对你有一定的参考价值。
新建前准备(新建完成公司的OU,部门,附新建命令):
New-ADGroup -Name ...
New-ADGroup -Name ... -Path “...”
Powershell模板属性
No,Account,Name,Company,SecondaryDepartment,TertiaryDepartment,EnglishName,Displayname,Surname,Givenname,OfficePhone,Mobile,Mail,Position
注意:CSV文件需保存为UTF-8格式,否则导入会为乱码
Powershell代码
#设置用户默认密码
$Password = ConvertTo-SecureString "[email protected]" -AsPlainText -Force
import-csv D:\Network\newaduser.csv | `
Foreach{
#根据三级部门和二级部门确定用户所在OU
If ( $_.TertiaryDepartment -gt "" )
{ $Path = "OU=" + $_.TertiaryDepartment + ",OU=" + $_.SecondaryDepartment + ",OU=Sanypalfinger,DC=Sanypalfinger,DC=com" }
Else
{ $Path = "OU=" + $_.SecondaryDepartment + ",OU=Sanypalfinger,DC=Sanypalfinger,DC=com" }
New-ADUser -Name $_.Name `
-SamAccountName $_.Account `
-Surname $_.Surname `
-Givenname $_.Givenname `
-Company $_.Company `
-DisplayName $_.Displayname `
-Office $_.No `
-Department $_.SecondaryDepartment `
-OfficePhone $_.OfficePhone `
-Mobile $_.Mobile `
-Title $_.Position `
-Path $Path `
-AccountPassword $Password `
-Enabled $true
#模板中三级部门为空处理,直接将用户加到二级部门用户组中
if ( $_.TertiaryDepartment -gt "" )
{ Add-ADGroupMember -Identity $_.TertiaryDepartment -Members $_.account }
else
{ Add-ADGroupMember -Identity $_.SecondaryDepartment -Members $_.account }
}
本文出自 “happygoes” 博客,请务必保留此出处http://happygoes.blog.51cto.com/5319054/1908168
以上是关于Powershell批量新建AD域账号的主要内容,如果未能解决你的问题,请参考以下文章