Script that can rename from CSV/serial join domain

360 pts.
Tags:
.CSV files
VBS
Hi, I'm after a script that would be able to rename a computer based on the machines serial number collected from the machine then i want it to look up the reference in a CSV file rename to the given name, add to the domain and reboot all automatically. Does anyone have such a script? I have this one below that can reset the computers name to be g_ what ever the serial number is but id like to rename the machines to something friendly now link g_room etc here is the old script first we run install, reboot the machine and away it goes. INSTALL.VBS: Option Explicit Dim objFSO, objFileCopy, objGuyFile, wshshell, RegKey Dim strFilePath, strDestination, strFilePath2, strDestination2 Dim strFileText, strFileText2, strFileText3 Dim objFolder, objShell, strDirectory, objWSHShell ' declaring reg values below Dim strcomputer, stdOut, oReg, strKeypath, strValueName, strValue, dwvalue ' what folder to create to copy install files to strDirectory = "c:\windows\reimage" ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Note If..Exists. Then, Else ... End If construction If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) End If '-----------------copy install files------------------------ ' note e is my memory stick strFilePath = "e:\scripts\KPScript\netdom.exe" strFilePath2 = "e:\scripts\KPScript\rename.vbs" strDestination ="c:\windows\reimage\netdom.exe" strDestination2 ="c:\Documents and Settings\All Users\Start Menu\Programs\Startup\rename.vbs" Set objFSO = CreateObject("Scripting.FileSystemObject") ' copy first file Set objFileCopy = objFSO.GetFile(strFilePath) objFileCopy.Copy (strDestination) ' copy second file Set objFileCopy = objFSO.GetFile(strFilePath2) objFileCopy.Copy (strDestination2) ' -----------------set autologon --------------------------- const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set StdOut = WScript.StdOut Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" strValueName = "DefaultUserName" strValue = "administrator" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "DefaultPassword" strValue = "Enter admin password" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "AutoAdminLogon" strValue = "1" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "DefaultDomainName" strValue = "Enter Domain Name" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue '---------------set reimage step process in registry-------- strKeyPath = "SOFTWARE\reimage" oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath strValueName = "STEP" strValue = "1" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue '---------------------Restart PC------------------------------ 'set objWSHShell = WScript.CreateObject("WScript.Shell") 'objWSHShell.Run "shutdown.exe /r" wscript.echo "Install complete" Wscript.Quit RENAME.VBS were 5100_ is the start before serial Option Explicit Dim objWMIService, colComputers, objComputer, strComputer, objFileSystem, delay Dim NewName, Result, currentstep, oWshShell, objWSHShell dim computername, serial, snset, winmgmt1, nameou, fullname, WshNETWORK, oldname, WSHShell, SN ' -------------declare registry values------------------------------------------- Dim RegKey, stdOut, oReg, strKeypath, strValueName, strValue, dwvalue ' -------------declare netdom values--------------------------------------------- Dim strDomainAccount delay = "5" Set oWshShell = CreateObject("WScript.Shell") Set WSHShell = CreateObject("WScript.Shell") RegKey = "HKLM\SOFTWARE\reimage\" ' path to made up results currentstep = WSHShell.RegRead (regkey & "STEP") ' step is the made up name of which step the pc is up to '-----------------------------Get computer serial number and make a new computername and reboot---------------- nameou = "5100_" strComputer = "." Set WshNetwork = WScript.CreateObject("WScript.Network") oldname = WshNetwork.ComputerName ComputerName = oldname If currentstep = 1 Then winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &"" Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS") for each SN in SNSet serial = SN.SerialNumber fullname = nameou + serial Next NewName = fullname If NewName = "" Then WScript.Quit(10) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputers = objWMIService.ExecQuery _ ("SELECT * FROM Win32_ComputerSystem") For Each objComputer in colComputers Result = objComputer.Rename(NewName) If Result = 0 Then Else End If Next WSHShell.RegWrite regkey & "STEP", 2 ' changes the value of Step to 2 'reboot pc Else If currentstep = 2 then WSHShell.RegWrite regkey & "STEP", 3 ' changes the value of Step to 3 delay = "30" ' ***************get rid of autologon const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set StdOut = WScript.StdOut Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" strValueName = "DefaultUserName" strValue = "" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "DefaultPassword" strValue = "" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "AutoAdminLogon" strValue = "0" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "DefaultDomainName" strValue = "ENTER DOMAIN HERE" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue ' ***************add pc to domain with netdom 'Variables to pass to netdom strDomainAccount = "ENTER DOMAIN HERE" 'run the netdome utility oWshShell.Run "C:\windows\reimage\netdom.exe join /d:" & strDomainAccount & " " & computername Set objFileSystem = CreateObject("Scripting.fileSystemObject") objFileSystem.DeleteFile Wscript.ScriptFullName,True 'else ' If currentstep = "3" Then 'Else ' End If End If End If set objWSHShell = WScript.CreateObject("WScript.Shell") objWSHShell.Run "shutdown.exe /r /t " & delay WScript.Quit(Result) I want to be able to rename from serial to a given name all automatically referencing to a csv would be nice, can anyone help???

Software/Hardware used:
windows 2008, windows 7
ASKED: July 12, 2012  6:56 AM
UPDATED: November 9, 2012  3:33 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

http://sourceforge.net/projects/admanag

This is a tiny tool I wrote for the sole purpose of renaming machines according to their MAC address (from CSV file) and joining the domain afterwards without any interaction… It’s tiny and gets the job done ;) I hope It helped…

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following