How to rename a useraccount in Active Directory with Kix.

What am i doing wrong with the userPrincipalName because in active directory it isn't accepted

script :


CLS

Debug Off
SetConsole("HIDE")

Dim $Filter[0]
$Filter[0]="User" ; Or replace "Group" with "User" or "Computer"

$ou = GetObject("LDAP://OU=Normal users,OU=UserWithOldGPO,OU=Users,OU=EU,OU=Europe,DC=eu,DC=firma,DC=corporate")
$ou.Filter = $Filter

$StrOldUserID = XlsInputBox("Give Old UserID to Convert ?","Question","")

If NOT $StrOldUserID
Exit
EndIf

$StrNewUserID = XlsInputBox("Give New UserID ?","Question","EU0")

If NOT $StrNewUserID
MessageBox("Please Give NEW UserID !","Warning",16)
Exit
EndIf

$Found = 0
For Each $User in $ou
If Ucase($User.sAMAccountName) == UCase($strOldUserID)
$User.sAMAccountName = $strNewUserID $User.userPrincipalName "test@eu.firma.corporate"
$User.SetInfo
MessageBox($User.Name + " changed ","Info",32)
$Found = 1
Endif
Next

If NOT $Found
MessageBox("User Not Found !","Warning",16)
Exit
EndIf

;Excel Inputbox function
Function XlsInputBox($prompt, optional $title, optional $default, optional $Left, optional $top, optional $type)
Dim $xls
$xls = CreateObject("Excel.application")
If $xls
If VarType($default) = 0
$default = ""
EndIf
If VarType($type) = 0
$type = 2
EndIf
$XlsInputBox = $Xls.Inputbox($prompt,$title,$default,$Left,$top,,,$type)
$Xls.Quit
$Xls = 0
EndIf
EndFunction