Pre-new Preparation (new complete company OU, Department, new command):
New-adgroup-name ...
New-adgroup-name ...-path "..."
PowerShell Template Properties
No,account,name,company,secondarydepartment,tertiarydepartment,englishname,displayname,surname,givenname, Officephone,mobile,mail,position
Note: The CSV file needs to be saved in UTF-8 format, otherwise the import will be garbled
PowerShell Code
#设置用户默认密码
$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
#模板中三级部门为空处理, add users directly to level two departmental user groups
if ($_. Tertiarydepartment-gt "")
{add-adgroupmember-identity $_. Tertiarydepartment-members $_.account}
Else
{add-adgroupmember-identity $_. Secondarydepartment-members $_.account}
}
This article is from the "happygoes" blog, make sure to keep this source http://happygoes.blog.51cto.com/5319054/1908168
PowerShell batch new ad domain account