Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming workstations using a script

Status
Not open for further replies.

neutec

Technical User
Apr 26, 2003
343
Hello everyone,
I would like to rename all of my workstations within my domain to the same name as the login name being used. Example ohn logs in and his computer is renamed john.doamin.local. Is this possible to do with a script that I can send down through a GPO?
 
Yes. It can be done, but before proposing an answer I have a question...

Let's say you have 2 users, Bob and Alice. When Bob logs into his machine, you want a script to change the computer name to his name. There's 3 basic problems here:
1) This will require a reboot. Forcing Bob to wait to use his system.
2) If Alice's system is broken and she uses Bob's, his workstation will be renamed, and her workstation will be completely booted out of the domain (if the name change is permitted at all). Once again, the user will be forced to wait for a reboot.
3) You will have to place administrator credentials in clear text in a script, which a technically savvy person could use to gain elevated privileges in your network.

So now the question: Why?


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
PScottC,
Thanks for your reply. Yes I see your point. Ive seen scripts that can do something simillar to this that use a temp login which is disabled after a few days. I would also need the script to be removed after a day or so to prevent the workstation being renamed if another user uses it.

How would you go about rename 100 workstation, one by one?
 
Ok... I just wanted to make sure that you knew what you were getting into.

The simple answer is, yes, you can do it with a script. There is a really good example here: [URL unfurl="true"]http://techtasks.com/code/viewbookcode/1646[/url]

This code can be modified to do what you want. If you have a good mapping of what computer belongs to who, I would suggest that you setup this script to use a text file (.csv) to rename the machines remotely. This would keep you from having to distribute an admin password across the network and the script would only execute one time.

Let me know if you need help revising the script.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
PScottC,
Thanks for the tip. I looked over the code and it looks pretty straight forward, however I’m not sure how to integrate a text file (.csv) into it. I’m assuming I would first need to know all of the existing machines names, which I should be able to obtain fairly easy, than I would use the script to compare the current name to the list to the name I would like to change it to. Is that correct? Do you know how I would modify this script to do that? Thanks again for the great link and support
 
Sure...

Build a simple file in Excel with 2 columns, oldname and newname. Create your list and save it as a .csv file. Your date will now be in the form of "oldname,newname".

Use VBScripts File System Object to open the text file and loop through all the lines.

Code:
Dim objFSO, objInputFile, strLine, strOldName, strNewName

Const ForReading = 1
Const strInputFile = "C:\Input.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(strInputFile, ForReading)

Do Until objInputFile.AtEndOfStream
	strLine = objInputFile.ReadLine
	strOldName = Mid(strLine, 1, InStr(strLine, "," -1))
	strNewName = Mid(strLine, InStr(strLine, "," +1), 20)
	
[b][red]<Insert Existing Code Here>[/red][/b]
Loop

Note: The InStr function that I use gives the position of the comma character in the string, so to get the Old name I need to stop reading the string at the character before the comma.

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top