Page 1 of 1 1
Topic Options
#118916 - 2004-05-03 05:40 PM How to rename a useraccount in Active Directory
FeReNGi Offline
Lurker

Registered: 2003-08-07
Posts: 3
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

Top
#118917 - 2004-05-03 07:46 PM Re: How to rename a useraccount in Active Directory
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Welcome to the board..

Commented out -
Code:

;BREAK ON
;CLS

;DEBUG OFF
;SetConsole("HIDE")



To see what is going on.

If you want to run this more cleanly, try using WKIX32.EXE.

Changed -
Code:

$ou.filter = $filter



To -
Code:

$ou.filter = $filter[0]



Why do you have -
Code:

IF Ucase($user.samaccountname) == UCase($strolduserid)



I changed this to -
Code:

IF Ucase($user.samaccountname) = UCase($strolduserid)



Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#118918 - 2004-05-03 08:13 PM Re: How to rename a useraccount in Active Directory
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
are you sure about that?

Quote:

$ou.filter = $filter[0]




the .filter needs to be an array value, and that was what he was passing in his original code..

ok i m sure that his original code will work using that as a filter.

Code:

$ou = getobject("WinNT://@domain")
dim $filter[0]
$filter[0]="user"
$ou.filter = $filter
for each $User in $ou
? $user.name
next




Top
#118919 - 2004-05-03 08:18 PM Re: How to rename a useraccount in Active Directory
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
somethign is wrong with this line here...

Quote:


$User.sAMAccountName = $strNewUserID $User.userPrincipalName "test@eu.firma.corporate"





something about it just does not look right for kix....

Top
#118920 - 2004-05-03 08:18 PM Re: How to rename a useraccount in Active Directory
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try doubling the "@" in the email address.

Also renaming the container is accomplished via the "MoveHere" method.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#118921 - 2004-05-03 09:44 PM Re: How to rename a useraccount in Active Directory
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think Brice is onto to something... the line is suspicious looking. Not sure what he is trying to do with it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#118922 - 2004-05-04 12:15 AM Re: How to rename a useraccount in Active Directory
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
well...

$User.sAMAccountName = $strNewUserID $User.userPrincipalName "test@eu.firma.corporate"

looks like

$User.sAMAccountName = $strNewUserID
$User.userPrincipalName "test@eu.firma.corporate"

where

$User.userPrincipalName "test@eu.firma.corporate"
should be
$User.userPrincipalName = "test@@eu.firma.corporate"

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#118923 - 2004-05-06 12:07 AM Re: How to rename a useraccount in Active Directory
FeReNGi Offline
Lurker

Registered: 2003-08-07
Posts: 3
Is the userprincipal name with this code

$User.userPrincipalName = "test@@eu.firma.corporate"

transformed to TWO fields in Active Directory ?

>>Also renaming the container is accomplished via >>the "MoveHere" method.

Explain above ?

Top
#118924 - 2004-05-06 12:26 AM Re: How to rename a useraccount in Active Directory
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
No, the "@" symbol is a special character in KiXtart used for Macros. To use a "@" symbol in a string, it must be doubled-up (e.g. "@@").

The MoveHere method is used by ADSI to move/rename user accounts. Here is an explanation from MSDN: IADsContainer::MoveHere

Top
#118925 - 2004-05-06 02:23 PM Re: How to rename a useraccount in Active Directory
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Looking at Page 26 of the 4.22 Document, we see the explanation about doubling these and other characters for use in KiXtart..

Optionally, you could use -

Code:

$rc=SetOption("NOVARSINSTRINGS","ON")



The document also talks about this right above where it talks about doubling these characters.

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#118926 - 2004-05-07 01:27 PM Re: How to rename a useraccount in Active Directory
FeReNGi Offline
Lurker

Registered: 2003-08-07
Posts: 3
Try doubling the "@" in the email address.

is the solution !

I replaced it by $User.userPrincipalName = $strNewUserID + "@@eu.firma.corporate"

Thnx guys

If you want to make a UDF from it go ahead....

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.062 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org