I am using PS to add users to AD using input data from a CSV file, but I keep getting the error:
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
}
}
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.
The problem was with the OUPath in the input data:
changed to
Everything works