Page 1 of 1 1
Topic Options
#63631 - 2002-03-07 03:45 PM Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
We are starting a project to rename around 1500 users login name. This is on a NT4 domain. Is there a way for kix to read a .txt file or any other file and see old name and new name and change it? I have seen it done with single users, but need to do multiple users at one time.

Thanks.

Top
#63632 - 2002-03-07 04:26 PM Re: Renaming Accounts
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
here is something to work off of...

you will need this UDF UserRename() and the security rights to make these changes.

the userfile looks something like this.

code:
;old name,new name
;you may use ; to comment out lines in this file.

mroot2,Mroot
james2,james
testuser2,testuser

here is the kix code.

code:
$usersfile = "users.txt"

$nul = open(1,$usersfile,2)

$userdata = readline(1)
do
select
case substr($userdata,1,1) = ";" or instr($userdata,",") = 0
;ignore this line
case 1
$userdata = split($userdata,",")

if ubound($userdata) <> 1 ? "Please check the $userfile for bad data" exit(1) endif

$error = userrename(@domain,$userdata[0],$userdata[1])

if @error = 0
? "User " + $userdata[0] + " Renamed to " + $userdata[1] color g+/n " OK" color w/n
else
? color r+/n "ERROR RENAMING " + $userdata[0] + " TO " + $userdata[1] + " @error:@serror" color w/n
endif


endselect
$userdata = readline(1)
until @error <> 0

Bryce

[ 07 March 2002, 16:30: Message edited by: Bryce ]

Top
#63633 - 2002-03-07 04:30 PM Re: Renaming Accounts
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
oops...

I changed this line

$error = userrename(@wksta,$userdata[0],$userdata[1])

to be

$error = userrename(@domain,$userdata[0],$userdata[1])

this will point to the domiain...

Top
#63634 - 2002-03-07 04:38 PM Re: Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
Thanks Bryce, I'll give it a try.
Top
#63635 - 2002-03-07 05:58 PM Re: Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
I get a "1:COM exception error..." Any thoughts?
Top
#63636 - 2002-03-07 06:58 PM Re: Renaming Accounts
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
With Bryce`s permission, may I ask what OS your running your script on ? - If Windows NT or 9x, you have to install the ADSI runtime - avaiable free from Microsoft ...

-Shawn

Top
#63637 - 2002-03-07 08:18 PM Re: Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
Duh...I forgot all about that. Thanks to both of you.
Top
#63638 - 2002-03-07 09:07 PM Re: Renaming Accounts
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Thanks Shawn! I have come to feel like we have always had ADSI [Big Grin]

rc10t, If i may ask...

what are you renaming to? I am guessing that you are wanting to implement a user id naming convention like first initial plus first 7 letters of the last name.

I am also guessing that your current naming convention is all over the map....for three Bill Smiths you have a smith, smithb, bsmith....

with some feedback, a script that does not need a txt file might be able to be created.

Bryce

[ 07 March 2002, 21:09: Message edited by: Bryce ]

Top
#63639 - 2002-03-07 09:19 PM Re: Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
Actually we currently use a first initial next seven of last name. If there is a duplicate then middle i is used. But the company is consolidating domains, so everyones id will become their employee number. What a mess if you ask me. Is there a way to change the profile path id exist to the new id as well? We use roaming profiles for our Terminal Server users. And also do a home folder rename?
Top
#63640 - 2002-03-07 10:30 PM Re: Renaming Accounts
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
yes, both of these settings can be changed via ADSI.

here is some code...

code:
$userdata = split("mroot,Mroot",",")
$profile = "new profile"
$homedirectory = "new home directory"

$UserOBJ = GetObject("WinNT://@domain/"+$userdata[1]+",user")
if vartype($UserOBJ) = 9 and @error = 0

;here is the profile
$userobj.put("Profile","$profile")
if @error = 0
$userobj.SetInfo
else
? "Error setting profile"
endif

;here is the HomeDirectory
$userobj.put("HomeDirectory","$homedirectory")
if @error = 0
$userobj.SetInfo
else
? "Error setting homedirectory"
endif

endif

Bryce

Top
#63641 - 2002-03-28 09:49 PM Re: Renaming Accounts
Anonymous
Unregistered


FYI ... You can redirect Windows 2000 to your old profile by editing the registry. Open the Registry Editor and then open the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.
Under this branch, locate the key that contains your profile settings. The easiest way to identify the correct key is to check the value of
ProfileImagePath in the key and locate the one pointing to your current profile directory. Then, edit the value of ProfileImagePath to point to the
old profile path. Log off and log back on; this should restore your original profile.

Top
#63642 - 2002-04-10 06:23 PM Re: Renaming Accounts
rc10t Offline
Fresh Scripter

Registered: 2002-01-24
Posts: 20
How can you get this to report errors to a log file using the rename udf?
Top
#63643 - 2002-04-10 07:11 PM Re: Renaming Accounts
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
UserRename() will return an @error value

you can either use writeline() to write to an open file or...

something like this.

shell '%comspec% /c echo @error:@serror >> error.txt'

i think that there are even some Log Error type UDF's available.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 840 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.061 seconds in which 0.023 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