无法在Windows Server 2012 R2上使用New-ADUser在AD中添加用户

时间:2019-04-07 08:14:56

标签: powershell active-directory

我一直在尝试通过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

0 个答案:

没有答案