2

I've inherited this stupid name convention:

COMPANYNAME-CITY20090724 or COMPANYNAME-CITY-JOHN

It doesn't tell me anything about the location (floor, department). John left the company months ago. Computers from one city moved to another city, but the name hasn't been changed.

How can you rename 100+ computers when you want to create a new naming convention?

Jindrich
  • 4,968
  • 8
  • 30
  • 42

4 Answers4

5

Sure thing. The NETDOM utility is "your friend" in this case. You can use a startup script to rename computers.

Some docs on NETDOM are here:

I could see a really simplistic script like this:

@echo off
IF "%COMPUTERNAME%"=="COMPANYNAME-CITY-JOHN" SET NEWNAME=NEWNAME-HERE
IF "%COMPUTERNAME%"=="COMPANYNAME-CITY-BOB" SET NEWNAME=NEWNAME-HERE2
... more machines ...
IF NOT "%NEWNAME%"=="" NETDOM renamecomputer member /newname:%NEWNAME% /userd:USER-TO-PERFORM-RENAME-UNDER /password:PASSWORD-FOR-THAT-USER

Once all the computers are renamed you can take the startup script away. It shouldn't be too "expensive" to run on computers that have already been renamed. If you were worried about that you could do the "trapdoor" technique whereby the script ends with the computer placing itself into a group that has been denied rights to execute the script.

  • Create a group in AD-- say "Computer Rename Complete".
  • Modify the permission on the group to include "Domain Computers - Write / Add Self as Member"
  • In the simplistic batch-file script above add the line at the end:
IF NOT "%NEWNAME%"=="" NET GROUP "User Creation Script Complete" /DOMAIN /ADD %COMPUTERNAME%$

You'll see that group "grow" member computers as it runs on each machine. To stop the script from running on computers where it's already run, add a permission to the GPO that assigns the startup script "Computer Rename Complete - Deny Apply Group Policy". Then the script will run once on each machine.


What are your destination names going to be like? If you're like me and like Dell service tag numbers you could do something like this (in VBScript):

Option Explicit
Dim objWMIService, strNewName, objShell, objNetwork
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

' Obtain the service tag
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
For Each objSMBIOS in objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
    strNewName = objSMBIOS.SerialNumber 
Next

' Check for empty string
If (strNewName = "") Then WScript.Quit

' Does the computer need to be renamed?
If (UCase(strNewName) <> UCase(objNetwork.ComputerName)) Then    
     objShell.Run "NETDOM renamecomputer member /newname:" & strNewName & " /userd:USER-TO-PERFORM-RENAME-UNDER /password:PASSWORD-FOR-THAT-USER"
End If

That script could just run all the time, and would constantly rename computers that weren't named based on their service tags... heh heh. (I'm not sure that I'd actually do that, and if I did I'd put more sanity checking in the script.)

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
2

You could do this through PowerShell. In Excel, make a file with two columns, one for the old name, one for the new name. Add a header row oldname and newname. Save it as a CSV (mylist.csv) then run this in powershell:

function renameAndReboot([string]$computer, [string]$newname)
{
        $comp = gwmi win32_computersystem  -computer $computer
        $os   = gwmi win32_operatingsystem -computer $computer

        $comp.Rename($newname)
        $os.Reboot()
}

Import-Csv mylist.csv

foreach ($entry in $list)
{
    renameAndReboot($entry.oldname,$entry.newname)
}

...core code came from here.

Adam Brand
  • 6,127
  • 2
  • 30
  • 40
  • 1
    Assuming all the computers are powered-on and reachable over the network at the time you run that script it would work. – Evan Anderson Jul 24 '09 at 01:16
0

Computers from one city moved to another city, but the name hasn't been changed.

This is a weakness of naming schemes which attempt to describe location, owner, function, etc. Things change. So you end up either renaming computers often (and rebooting every time!), or having a naming scheme which falls into disrepair as time passes.

May I suggest the description field? alt text http://lh3.ggpht.com/BryanLockwood/SKbN8OdozVI/AAAAAAAAAVU/C3ZeLX0_wGc/%5C%5Ccojones.org%5Cfiles%5Cusers%5Cbryan%5CDesktop%5CComputerDescription.PNG?imgmax=512

You can list computers and their descriptions easily: alt text http://lh6.ggpht.com/BryanLockwood/SKbN8HBTywI/AAAAAAAAAVc/vu65Fm4R5aM/%5C%5Ccojones.org%5Cfiles%5Cusers%5Cbryan%5CDesktop%5Ccmd-example-descriptions.PNG?imgmax=512

More on this at my blog.

quux
  • 5,368
  • 1
  • 24
  • 36
  • It looked to me like the poster already knew that using location-dependent computer names was a bad idea-- hence the statement: "Computers from one city moved to another city, but the name hasn't been changed." Perhaps I read too much into the poster's statement, but it seemed to me like he knew that it wasn't a good idea to use location-dependent names. – Evan Anderson Jul 24 '09 at 12:00
  • Evan, maybe. The wording makes it hard to tell. But others will read this question, so I did want to suggest an alternative that seems to go often missed. I've seen a *lot* of orgs still trying to make location/function/user-based naming schemes work. – quux Jul 25 '09 at 20:51
0

If you are not familiar with the Netdom command line tool then try using the Netdom rename computer GUI from colosify.

It will help you rename multiple computers on your domain by uploading a .csv file without the need to remember or learn any command line code or create any scripts.

This GUI saved me a lot of time.

Dave
  • 1
  • 1