#164170 - 2006-07-11 03:48 AM
How to rename a useraccount in NT Domain
|
Mark Pietersz
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
|
|
|
|
#164172 - 2006-07-11 05:19 AM
Re: How to rename a useraccount in NT Domain
|
Shawn
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
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
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
|
|
|
|
#164177 - 2006-07-11 05:44 PM
Re: How to rename a useraccount in NT Domain
|
Shawn
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
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
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
|
|
|
|
#164181 - 2006-07-13 04:26 PM
Re: How to rename a useraccount in NT Domain
|
Howard Bullock
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.
|
|
Top
|
|
|
|
#164182 - 2006-07-13 05:36 PM
Re: How to rename a useraccount in NT Domain
|
backermann
Fresh Scripter
Registered: 2006-01-13
Posts: 6
|
Have you looked at cusrmgr.exe?
|
|
Top
|
|
|
|
#164184 - 2006-07-14 02:33 AM
Re: How to rename a useraccount in NT Domain
|
Mark Pietersz
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
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.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(StuTheCoder)
and 798 anonymous users online.
|
|
|