New-ADUser :服务器不愿意处理请求

时间:2021-04-21 01:57:39

标签: powershell active-directory powershell-1.0

我正在使用 PS 使用来自 CSV 文件的输入数据将用户添加到 AD,但我不断收到错误消息:"New-ADUser : The server is unwilling to process the request"

代码和 csv 将附在这篇文章中,任何导致解决方案的指针或见解将不胜感激!

Import-Module ActiveDirectory
$ar_user = Import-Csv \\JHanDomain.local\Home\IT\IT_Share\a10\users.csv    
foreach ($User in $ar_user)
{
    $uname = $User.Username
    $pw = $User.Password
    $Fname = $User.FirstName
    $Lname = $User.LastName
    $ou = $User.OUPath
    $desc = $User.Description
    $action = $User.Action
    $splat = @{
        Name=$Uname
        AccountPassword=(ConvertTo-SecureString $pw -AsPlainText -Force)
        GivenName=$Fname
        Surname=$Lname
        DisplayName="$FName $LName"
        Path=$ou
        Description=$desc
        Enabled=$true
        }
    if (Get-ADUser -F {AccountName -eq $Uname})
    {
        Write-Warning "User Already Exists!"
    }
    else 
    {
        New-ADUser @splat
    }
}

users.csv

编辑:当我从 Path=$ou 中删除 $splat 时代码有效,但我无法识别路径有什么问题。我尝试将“cn”切换为“ou”(在 CSV 文件中),但结果相同。路径本身是正确的。

1 个答案:

答案 0 :(得分:0)

问题在于输入数据中的 OUPath:

<块引用>

cn=Bus_IT,dc=JHanDomain.local,dc=local

改为

<块引用>

ou=Bus_IT,dc=JHanDomain,dc=local

一切正常