VBScript - How to Rename Active Directory Computer Name
Environment
Version
Introduction
Rename computer to be the wanted standard
Computer list should like this
Code
Run setting via netdom on the computer by administrator account
Reference
- Microsoft Active Directory
Version
- 2010-Jul-08
Introduction
Rename computer to be the wanted standard
Computer list should like this
Old Name,New Name
Desktop01,HOST01
Code
Run setting via netdom on the computer by administrator account
Const DEFAULT_HOSTS_LIST = "\\Server\netlogon\tmp\hostname.csv"Although netdom have parameter for setting via other accounts, tried not have any success, just getting the following failures
Const DEFAULT_NETDOM = "\\Server\netlogon\bin\netdom.exe"
'Waiting how long to reboot
Const DEFAULT_REBOOT = "60"
On Error Resume next
Set objntw = createobject("WScript.Network")
Set objshell = createobject("WScript.Shell")
strpc = UCase(objntw.ComputerName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTStream = objFSO.OpenTextFile(DEFAULT_HOSTS_LIST, 1, 1)
Do While objTStream.AtEndOfStream <> True
arline = Split(objtstream.ReadLine, ",")
If strpc = UCase(arline(0)) Then
newpc = UCase(arline(1))
str = DEFAULT_NETDOM & " renamecomputer " & strpc & " /newname:" & newpc & " /force /reboot:" & DEFAULT_REBOOT
objshell.Run str
End If
Loop
objTStream.close
Access is denied.
The command failed to complete successfully.
Logon failure: unknow user name or bad password.Due to this, find another way to set for the one not have administrator right. Running this via psexec, also can be via Altiris
Const DEFAULT_HOSTS_LIST = "\\Server\netlogon\tmp\hostname.csv"
On Error Resume Next
Set objntw = createobject("WScript.Network")
Set objWMIService = GetObject("Winmgmts:root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTStream = objFSO.OpenTextFile(DEFAULT_HOSTS_LIST, 1, 1)
strpc = UCase(objntw.ComputerName)
Do While objTStream.AtEndOfStream <> True
strline = objTStream.ReadLine
If strpc = UCase(arline(0)) Then
newpc = UCase(arline(1))
'Call always gets only one Win32_ComputerSystem object.
'http://msdn.microsoft.com/en-us/library/Aa393056
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
Return = objComputer.Rename(newpc)
If Return <> 0 Then
WScript.Echo "Rename failed. Error = " & Err.Number
Else
WScript.Echo "Rename succeeded." & _
" Reboot for new name to go into effect"
End If
Next
End If
Loop
objTStream.close
Reference