Monday, November 24, 2008

Renaming a Computer and Computer Account

Renames a computer and its corresponding Active Directory computer account. Requires Windows XP or Windows 2003 Server, and must be run on the local computer.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
    err = ObjComputer.Rename("WebServer")
    Wscript.Echo err
Next

This is a VB Script, this can be used by saving the file in .vbs file