CONST strDomainUser = "Domain\User" CONST strDomainPwd = "Password" CONST strDomain = "Domain" CONST strK1000SERVERNAME = "K1000 Server Name" Set wshShell = WScript.CreateObject( "WScript.Shell" ) 'Start Gather Serial Number From BIOS strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_BIOS") For Each objSMBIOS in colSMBIOS strSerial = objSMBIOS.SerialNumber Next 'End Gather 'Trapping for testing 'msgbox "Machine Serial is: " & strSerial 'msgbox "Machine Name will be: " & FetchSQLResult (strSerial) 'Set What The Machine Name Will Be strFutureName = FetchSQLResult (strSerial) 'Begin Renaming The Machine 'Capture Not Found Assets If strFutureName = "None Found" Then WriteToLog ("System - No ASSET Found , Prompting User Now") strFutureName = InputBox("Enter the Name for this PC:","Capturing Info...", strFutureName) End If Do While not OkToRename(strFutureName) strFutureNameg = InputBox("Enter the Name for this PC:","Capturing Info...", strFutureName) Loop 'Rename Process 'Ensures call always only gets one W32CompSys object For Each objComputer in _ objWMIService.InstancesOf("Win32_ComputerSystem") Return = objComputer.rename(strFutureName,strDomainPwd,strDomainUser) If Return <> 0 Then WScript.Echo "Rename failed. Error = " & Err.Number WriteToLog ("System - Rename Failed." & Err.Number) Else WriteToLog ("System - Rename Succeded!") End If Next 'Sub For Writing to a log file 'This writes lines to a log file for extra stepping information no debug info captured though Sub WriteToLog (messagetext) dim logFSO, imagelog Set logFSO = CreateObject("Scripting.FileSystemObject") Set imagelog = logFSO.OpenTextFile("C:\Image_Log.txt", 8, true) imagelog.WriteLine (Now & " - " & messagetext) imagelog.close END Sub 'End Sub for Writing to a log file 'Function to gather the asset name of the serial number from KACE 'You can modify this to receive command and input to re-use the function if you want 'NOTE You must change the connect string to match the driver you're using, it is read from the check above, could probably automate the change Function FetchSQLResult (Input) 'on error resume next Dim objConnection Dim objCommand Dim objResultSet Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") Set objResultSet = CreateObject("ADODB.recordset") Dim ConnectString ConnectString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=" & strK1000SERVERNAME & "; PORT=3306; DATABASE=ORG1; USER=R1; PASSWORD=box747; OPTION=3;" Dim ReturnVal objConnection.Open ConnectString With objCommand .CommandType = 1 .ActiveConnection = objConnection .CommandText = "select NAME as AssetName from ASSET inner join ASSET_DATA_5 on ASSET.ASSET_DATA_ID = ASSET_DATA_5.ID where ASSET.ASSET_TYPE_ID = 5 And ASSET_DATA_5.FIELD_34 = '" & Input & "' limit 1" Set objResultSet = .Execute End With if objResultSet.eof = true then ReturnVal = "None Found" WriteToLog ("System - NO ASSET FOUND FOR THIS SERIAL NUMBER") else ReturnVal = objResultSet("AssetName") WriteToLog ("System - Machine will be renamed to - " & ReturnVal) end if Set objCommand = Nothing Set objConnection = Nothing FetchSQLResult = ReturnVal end function 'Function to check if a Registry Key exists Function KeyExists(key) Dim objShell On Error Resume Next Set objShell = CreateObject("WScript.Shell") objShell.RegRead (key) Set objShell = Nothing If Err = 0 Then KeyExists = True End Function Function OkToRename(strPCName) wscript.sleep(5000) Set dso = GetObject("WinNT:") wscript.sleep(5000) Set objDomain = dso.OpenDSObject("WinNT://" & strDomain, strDomainUser, strDomainPwd, 0 AND 1) objDomain.Filter = Array("computer") OkToRename = TRUE For each oComputer in objdomain If oComputer.Name = strPCName then Response = MsgBox(strPCName & " already exists in AD. Do you want to delete it?", vbYesNo,"Name Aleady Exists.") If Response = vbYes Then objDomain.Delete "Computer", oComputer.Name wscript.sleep(5000) OkToRename = TRUE Else OkToRename = FALSE End If End If Next End Function