积极答复者
powershell 批量添加用户

问题
-
Import-Module ActiveDirectory
$Users = Import-Csv -Path 'E:\ps\User.csv'
foreach ( $User in $Users ) {
$Displayname = $Users.displayName
$UserFirstname = $Users.GivenName
$UserLastname = $Users.sn
$OU = $Users.OU
$SAM = $Users.SamAccountName
$UPN = $Users.UserPrincipalName
$Password = $Users.Password
$title = $Users.title
#$department = $Users.department
$department = $Users.department
New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName "$SAM" -UserPrincipalName "$UPN" -GivenName "$UserFirstname" -Surname "$UserLastname" -path "$OU" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -ChangePasswordAtLogon:$true -Enabled:$true
}嗨,请问上面的命令哪里有问题吗,通过这种方法创建用户出来,账户属性里,办公室和部门,职位都没有,但是命令运行没有报错
答案
-
您好,
感谢您的发帖。
根据您的描述,您所使用的命令中并没有办公室、部门和职位的相关信息,因此无法创建出相应属性。
部门是 -Department
办公室是 -Office
职位需要使用自定义属性 -OtherAttributes
详细信息请参考以下这个链接:
https://docs.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=winserver2012-ps
希望以上信息有所帮助。
Best regards,
Kallen
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已标记为答案 郭世昂 2018年11月27日 4:39
全部回复
-
您好,
感谢您的发帖。
根据您的描述,您所使用的命令中并没有办公室、部门和职位的相关信息,因此无法创建出相应属性。
部门是 -Department
办公室是 -Office
职位需要使用自定义属性 -OtherAttributes
详细信息请参考以下这个链接:
https://docs.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=winserver2012-ps
希望以上信息有所帮助。
Best regards,
Kallen
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已标记为答案 郭世昂 2018年11月27日 4:39