Question

Bulk change of User logon name Pre Windows 2000 -- sAMAcoountName

Asked by: gdemoura6555

Good afternoon Experts
I have a task to change the user logon name for all the users in my OU and eventually in our domain. Curently, logon format is A000001. A000002 and so on.  In AD properties for users, under Account Tab both User Logon Name and User Logon Name Pre-Windows 2000 have A000001 (Say for user Alan Jones).
Now I need to change logon account for all the users from A000xxx format to ABC000yyy. I have Tool from Dovestone which can import the data from a file and User Logon name but it cant change User Logon Name Pre-Windows 2000.
All the client system are on Win XP. But if I dont change the User Logon Name Pre-Windows 2000, it does not accept the new logon account say ABC00012. But it will logon with old account which is on Pre windows 2000 that is A000001.
I want a script which can copy new user account from "User Logon Name" to "User Logon Name Pre-Windows 2000" and hopefully after user can logon with new account name ABC00yyy.

If anyone has different opinion I can try that.

Thanks
CJ  

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-04-16 at 13:58:50ID23328899
Tags

AD

,

script

,

Pre Windows 2000

,

sAMAcoountName

,

user logon name

Topics

Active Directory

,

Windows 2000 Server

,

Windows 2003 Server

Participating Experts
1
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. for CJ
    Thanks for your help CJ
  2. Logon Script: Install printer according to the OU.
    I have a logon script that is currently working but want to make some changes. I have an OU (Workstations) which contains computer accounts. If the computer is in that OU the logon script will map a printer. I want to have be able to access sub OUs OU: Workstations -OU: O...
  3. Set Logon Hours Per OU
    Is there a way to set the logon hours for multiple users per group or OU?
  4. OU's and cached logons
    On a Windows 2003 AD domain, is there a tool to allow one to do different cached logon rules for different OU's?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Chris-DentPosted on 2008-04-17 at 03:48:06ID: 21375751


Hey CJ,

Not too hard to do, the script below is VbScript, you'll need to save it off as .vbs.

It doesn't make any changes at the moment, that bit is commented out until you've had a chance to see what it does.

I recommend you run it with this on the command line:

cscript scriptname.vbs

It means all the things it tells you appear on the command line rather than as lots of popup windows.

HTH

Chris


Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
 
Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT sAMAccountName, userPrincipalName, distinguishedName " &_
	"FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") &_
	"' WHERE objectClass='user' AND objectCategory='person'"
Set objRootDSE = Nothing
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
 
While Not objRecordSet.EOF
	' User Principal Name is the "User Logon Name"
	strUPN = objRecordSet.Fields("userPrincipalName").Value
 
	' User Principal Name is in the format username@domain.com. Grab the first part only.
	strUsername = Split(strUPN, "@")(0)
 
	' SAM Account Name is the "User Logon Name Pre-Windows 2000"
	strSAMAccountName = objRecordSet.Fields("sAMAccountName").Value
 
	' If the first bit of the UPN isn't the same as the SAMAccountName it'll be changed
	If strSAMAccountName <> strUsername Then
		' Connect to the user account in AD
		Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName"))
		
		WScript.Echo "Resetting SAMAccountName for " & objUser.Get("name") &_
			" : Old: " strSAMAccountName & " New: " & strUsername
 
		' These lines make and commit the change. Check it does what you want first!
		' objUser.Put "sAMAccountName", strUsername
		' objUser.SetInfo
 
		' Disconnect from the User
		Set objUser = Nothing
	End If
	objRecordSet.MoveNext
Wend
 
objConnection.Close
 
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:

Select allOpen in new window

 

by: gdemoura6555Posted on 2008-04-17 at 08:30:43ID: 21378226

Hi Chris
I was expecting reply from you. U seem to be Guru in scripting :)
I saved the above script as cs.vbs file and tried from command prompt csript cs.vbs which didnt work. Also I tried to execute it directly but it shows error on line 38 (file attached) . I am not that comfortable with vb scripting. I am also referring to your solution in previous post
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/2000/Q_22050926.html?sfQueryTermInfo=1+2000+copi+from+logon+name+pre+user+window

I have test environment where I can test your script. Also I need to run this script on users in specific OU only. Your help is greatly appreciated

Thanks
CJ

 

by: Chris-DentPosted on 2008-04-17 at 08:56:06ID: 21378498


Hey CJ,

Sorry about that, should remember to run syntax checks on my code before posting. It works now.

Executing on a single OU involves modifying this (long) line:

objCommand.CommandText = "SELECT sAMAccountName, userPrincipalName, distinguishedName " &_
        "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") &_
        "' WHERE objectClass='user' AND objectCategory='person' AND userPrincipalName='*'"

This is the bit we use to tell it which accounts to get. I've used RootDSE to get some basic information about the domain to avoid hard-coding it.

If we wanted to execute the script on:

yourdomain.local\Accounts\BobsOffice\Users

We would need to change that line to:

objCommand.CommandText = "SELECT sAMAccountName, userPrincipalName, distinguishedName " &_
        "FROM 'LDAP://OU=Users,OU=BobsOffice,OU=Accounts," &_
        objRootDSE.Get("defaultNamingContext") &_
        "' WHERE objectClass='user' AND objectCategory='person' AND userPrincipalName='*'"

It still fills in the domain name part itself, but needs to be told the rest. Remember that it must include the trailing "," on the end of the custom path. It's combining that with DC=yourdomain,DC=local, it wouldn't like it without the comma.

Minor point of interest / explanation. The underscore (_) tells the script to continue onto the next line as if there were no line break. VbScript assumes you've finished the command at the end of the line otherwise.

I hope that makes some sense! If not, just post back with the path you want to use and I'll show you the modification.

Chris

Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
 
Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT sAMAccountName, userPrincipalName, distinguishedName " &_
        "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") &_
        "' WHERE objectClass='user' AND objectCategory='person' AND userPrincipalName='*'"
Set objRootDSE = Nothing
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
 
While Not objRecordSet.EOF
        ' User Principal Name is the "User Logon Name"
        strUPN = objRecordSet.Fields("userPrincipalName").Value
 
	' User Principal Name is in the format username@domain.com. Grab the first part only.
        strUsername = Split(strUPN, "@")(0)
 
        ' SAM Account Name is the "User Logon Name Pre-Windows 2000"
        strSAMAccountName = objRecordSet.Fields("sAMAccountName").Value
 
        ' If the first bit of the UPN isn't the same as the SAMAccountName it'll be changed
        If strSAMAccountName <> strUsername Then
                ' Connect to the user account in AD
                Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName"))
                
                WScript.Echo "Resetting SAMAccountName for " & objUser.Get("name") &_
                        " : Old: " & strSAMAccountName & " New: " & strUsername
 
                ' These lines make and commit the change. Check it does what you want first!
                ' objUser.Put "sAMAccountName", strUsername
                ' objUser.SetInfo
 
                ' Disconnect from the User
                Set objUser = Nothing
        End If
        objRecordSet.MoveNext
Wend
 
objConnection.Close
 
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:

Select allOpen in new window

 

by: gdemoura6555Posted on 2008-04-17 at 10:59:52ID: 21379639

Thanks Chris you rock!
Can you tell me how can I execute it its just report now. How can I check the changes in AD guess I need to change some line which is commented. Also can you send me links or site to refer about windows scripting. Curious to learn abt it. Last but not the least , the script just changes sAMAccountname only nothing else correct?
If possible send me the details of commands used in above script.

Thanks
CJ

 

by: gdemoura6555Posted on 2008-04-17 at 11:01:06ID: 31449537

Hey Champ send few links where I can start learning scripting. Thanks again

 

by: Chris-DentPosted on 2008-04-17 at 11:42:40ID: 21380052


:)

Correct, it only changes the SAMAccountName. The lines we need are these:

                ' These lines make and commit the change. Check it does what you want first!
                ' objUser.Put "sAMAccountName", strUsername
                ' objUser.SetInfo

Apostrophe is the comment character, we we just need to make them into:

                ' These lines make and commit the change. Check it does what you want first!
                objUser.Put "sAMAccountName", strUsername
                objUser.SetInfo

Which makes it do things.

Verification will just be by clicking on things, provided it doesn't come up with any errors :)

Learning though, I strongly recommend you look into PowerShell rather than VbScript. VbScript can do lots, but PowerShell can do more (Exchange 2007 and Server 2008 all make good use of it). The only downside is it won't work on Windows 2000, so a bit of a disappointment if you need to look after that.

Now learning resources, they're a tricky one for me. I don't really do the whole structured learning thing, I jump right in at the deep end and see if I can swim from there. Fortunately, not everyone has so little discipline, fellow expert and MVP Brandon has a tonne of links in his profile for places to begin:

http://www.experts-exchange.com/M_4238767.html

And you'll need to download it, of course :)

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

I'm still quite happy to explain the script above in detail if you'd like, just let me know. But if you only want it to start learning scripting I'd recommend you don't worry about it.

Incidentally, if it's helpful I can rewrite the script above into PowerShell to give you an idea of it all?

Chris

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...