Hi.
In case the SamAccountName length is greater than 20 chars, SetInfo() fail on each try in the foreach loop with the weird error: "A device attached to the system is not functioning"
`
create user
if ($user_account.length -lt 21)
{
$user_obj = $ou_obj.Create("user", "cn=$user_name")
$user_obj.Put("sAMAccountName", "$user_account")
$user_obj.Put("userprincipalname", "$user_account@$domain_name")
$user_obj.Put("description", $user_description)
$user_obj.put("pwdLastset",-1)
$user_obj.SetInfo()
$user_obj.SetPassword("$password")
$user_obj.SetInfo()
$user_obj.psbase.InvokeSet('FirstName',$first)
$user_obj.SetInfo()
$user_obj.psbase.InvokeSet('LastName',$last)
$user_obj.SetInfo()
$user_obj.psbase.invokeset("AccountDisabled", "False")
$user_obj.SetInfo()
$currentUAC = int
$newUAC = $currentUAC -bor 65536
$user_obj.put("userAccountControl",$newUAC)
$user_obj.SetInfo()
Write-Host -foregroundcolor green "- User $user_name has been created with $ptype password "
}
else
{
write-Host -ForegroundColor red "Error: Unable to Create $user_name . SamAccountName must be 20 chars or less. Size:$user_account.length"
}`