New-ADUser : The server is unwilling to process the request

2.2k views Asked by At

I am using PS to add users to AD using input data from a CSV file, but I keep getting the error: "New-ADUser : The server is unwilling to process the request"

The code and csv will be attached to this post, any pointers or insight leading to a solution will be appreciated!

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

Edit: The code works when I remove Path=$ou from $splat but I can't identify anything wrong with the path. I've tried switching "cn" for "ou" (in the CSV file) but same results. The path itself is correct.

1

There are 1 answers

0
herryJan On

The problem was with the OUPath in the input data:

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

changed to

ou=Bus_IT,dc=JHanDomain,dc=local

Everything works