Sandy Wood said:
Our network has over 900 XP systems that we need to rename. We're looking
for
a way to script or otherwise automate the process. We need to change a
single
character in the computer name to remove an underscore and replace it with
a
dash. We believe we can vbscript a search and replace script but beyond
that
have only begun to look into the process. Has anyone done anything like
this
before without physically visiting each system?
Below is an untested script I found in this newsgroup some
time ago. With a bit of tweaking it could do the job for you -
if it works! Alternatively you could try netdom.exe. Remember
that renaming each PC is only half the job - you also have to
rejoin it to your domain.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
strcomputer = InputBox("Enter New Computer Name")
If strComputer = "" then
Wscript.quit
End If
For Each objComputer in colComputers
err = objComputer.Rename(strComputer)
Next
'Joining a computer to a domain
'=========================
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = InputBox("Enter Domain name to Join")
strUser = InputBox("Enter Domain User to join domain")
strPassword = Inputbox("Enter password")
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" _
& strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _
& strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
"cn=Computers,DC=mydomain,dc=com", JOIN_DOMAIN + ACCT_CREATE)
If ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error.
Proceeding to change computer name. "
Else
MsgBox "Computer not added to domain successfully. Return value: " &
ReturnValue
End If