我一直在尝试通过Windows Server 2012r2中的CSV文件将用户批量加载到AD中,但是New-ADUser
总是抛出错误。我没有使用New-ADUser
中没有提到的任何属性,但是它不起作用。
代码是:
Import-Module ActiveDirectory
#set password
$password = ConvertTo-SecureString "xyzzy" -AsPlainText -Force
#enter file path of csv file
$filepath = Read-Host -Prompt "Please enter path"
$Users = Import-Csv $filepath
foreach ($User in $Users) {
$fname = $User.firstname
$lname = $User.lastname
$empid = $User.empid
$emailadd = $User.email
$username = $User.username
$ou = $User.ou
$location = $User.loc
$dept = $User.dept
New-ADUser -SamAccountName $username -Name $username -GivenName $fname -Surname $lname -UserPrincipalName "$fname@TEST.LCL" -Path $ou -AccountPassword $password -ChangePasswordAtLogon $True -EmailAddress $emailadd -Country $location -Department $dept -EmployeeID $empid
}
它不断抛出的错误是:
New-ADUser : The specified directory service attribute or value does not exist Parameter name: name At C:\Users\Administrator\Desktop\bulk.ps1:20 char:1 + New-ADUser -SamAccountName $username -Name $username -GivenName $fname -Surname ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-ADUser], ArgumentException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.NewADUser