Page 1 of 1 1
Topic Options
#164170 - 2006-07-11 03:48 AM How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Team

I need to write a script to rename local administrator user accounts on servers in our Windows NT/2000/2003 environment. I getting a bit confused as I've found articles on a variety of acronyms that I can't quite get a handle on, (WMI, ADSI, IADS etc). I've managed to write a script to extract user information starting with something like

Set Group = GetObject("WinNT://MyDomain/Administrators")

and using the Groupmembers code from this site.

But no doco that tells how to do the rename or methods that are available to this provider. However I'm sure it's there on the MS website, somewhere.

Can you suggest ways in which I might be able to achieve my goal

Regards

Mark

Top
#164171 - 2006-07-11 04:53 AM Re: How to rename a useraccount in NT Domain
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
http://home.comcast.net/~habullock/Perlutilities.htm
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164172 - 2006-07-11 05:19 AM Re: How to rename a useraccount in NT Domain
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here's that ADSI way you eluded to ...

Code:

Break On

$DOMAIN = @WKSTA
$OLDNAME = "JohnSmith"
$NEWNAME = "JaneDoe"

$objDomain = GetObject("WinNT://"+$DOMAIN)

$objUser = GetObject("WinNT://"+$DOMAIN+"/"+$OLDNAME)

$= $objDomain.MoveHere($objUser.AdsPath, $NEWNAME)

Exit 0


Top
#164173 - 2006-07-11 08:53 AM Re: How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Shawn - This is oh so close (and so simple) except for

When I login as JaneDoe am still using a profile directory that is called John Smith and the title from the start menu still says JohnSmith. This could be a little confusing later on in life for our network admins (even tho they are asking me to do this).

Is there a way to rename all the other JohnSmith stuff across to JaneDoe. If not would it be possible to copy JohnSmith to JaneDoe and then delete JohnSmith?

And where do guys learn all this stuff ? - amazing.

Cheers

Mark

Top
#164174 - 2006-07-11 09:21 AM Re: How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Thanks Les,

We would probably prefer a kix solution here rather than Perl given that people around here think that perl is something that comes out of an oyster. However there is source on your site that I will have a look at for myself.

Thanks

Mark

Top
#164175 - 2006-07-11 01:39 PM Re: How to rename a useraccount in NT Domain
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, I guess the big question is "SID History" here. Are you trying to simply rename the user account and preserve any ACL's to resources. If you create a new account and move values accross, imagine all of that would get thrown out the window - basically its a new user.
Top
#164176 - 2006-07-11 02:49 PM Re: How to rename a useraccount in NT Domain
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Actually, it is Howard's stuff, not mine and I was referring to the RenameAdmin.exe tool, not Perl script. I inferred from your request that you simply wanted to rename the Administrator accound for security reasons.

If you rename the users profile folder, it will create a new one with the new name. Then swap the folder names around.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164177 - 2006-07-11 05:44 PM Re: How to rename a useraccount in NT Domain
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, you can tweak the "optics" after-the-fact, like this:

Code:

$objUser = $objDomain.MoveHere($objUser.AdsPath, $NEWNAME)

$objUser.FullName = "Full name for " + $NEWNAME
$objUser.Description = "Description for " + $NEWNAME

$objUser.SetInfo

? @SERROR



Agreed though, the profile thing might be a little trickier.

Top
#164178 - 2006-07-13 06:28 AM Re: How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Guys,

I think that the goal would be to preserve ACL info (i will have to check with the network admins) so if there is no "save as" then the rename + prettying up the renamed user might be the go. I will then also have to check to see what they want to do about the profile directory.

The driver for this is (yet another) MS bug that we have found that relates to prviledges for local user accounts and not just admin accounts.

I'll get back soon

Cheers
Mark

Top
#164179 - 2006-07-13 08:12 AM Re: How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Have spoken to the admins and the straight account rename is cool. Can we also change the password ?
Top
#164180 - 2006-07-13 02:05 PM Re: How to rename a useraccount in NT Domain
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yup, you can change the password with this:

$objUser.SetPassword("xxxyyy!")

Top
#164181 - 2006-07-13 04:26 PM Re: How to rename a useraccount in NT Domain
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Les, I guess he either does not like "silver platter" solutions or just has not reviewed the program.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#164182 - 2006-07-13 05:36 PM Re: How to rename a useraccount in NT Domain
backermann Offline
Fresh Scripter

Registered: 2006-01-13
Posts: 6
Have you looked at cusrmgr.exe?
Top
#164183 - 2006-07-13 05:43 PM Re: How to rename a useraccount in NT Domain
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
When we did our NT4 to AD migration, we made extensive use of netdom, cusrmgr and Howard's RenameAdmin.exe tool.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164184 - 2006-07-14 02:33 AM Re: How to rename a useraccount in NT Domain
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Sorry Guys,

I really do appreciate the help. If it looks like I'm doing things the hard way it's only because I haven't found the easy way yet. I don't like asking questions that say 'please do my job for me' even though that's what i've done here. I'm actually a PeopleSoft developer who gets to do this kind of stuff maybe once every 12 months just because I can write code. I never get to be fluent at writing admin scripts nor knowing where to get 'the good stuff' (except this bbs of course) and our admins aren't really coders, more the deploy hotfixes and build server guys.

I didn't use RenameAdmin because the description for it says:

"Optionally renames and/or sets the password of the local [Builtin] 'administrator' account on the specified computer without knowing the original account name. This program requires administrator permissions on the target computer."

We are changing accounts other than 'administrator' that have local admin priviledges.

And I have finally found a useful reference for IADsUser under the Persistant Object Interfaces reference on MSDN.

Thanks again

Mark

Top
#164185 - 2006-07-14 02:54 PM Re: How to rename a useraccount in NT Domain
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Sorry, your original post mentions the need to renamed administrator accounts. ADSI as you found will give you the ability to accomplish your goals. Feel free to ask as many questions as you need or want.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


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

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

Generated in 0.066 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