Hello All,
could I please get you to review this script, The idea is to allow the techs to rename a computer remotely via the script. But this script is saying error,Any one please provide appropraite code?
Requirement :Rename the computer remotely
'this script loops through all the computers and runs the NETDOM command to rename the computer
'input file is computerstorename.txt is csv format (old name, new name)
Option Explicit
'On Error Resume NExt
Const ForReading = 1
Dim objFSO
Dim objShell
Dim objTextFile
Dim strLine, strComputerArray
Dim strCommand
Dim Return
Dim strValue
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objTextFile = objFSO.OpenTextFile("C:\computertorename.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
strComputerArray = Split(strLine,",")
'strComputerArray(0) is old name
'strComputerArray(1) is new name
'check if computer is online
If Ping(strComputerArray(0)) Then
'computer is online
strCommand = "NETDOM RENAMECOMPUTER " & strComputerArray(0) & " /NewName:" & strComputerArray(1) & " /Force /REBoot:60"
Wscript.echo strCommand
objShell.Run strCommand,1,true
'wait for 6 seconds
wscript.sleep(6000)
Return = objShell.Run (strCommand,1,true)
Wscript.echo strComputerArray(0) & " renamed to " & strComputerArray(1)
strValue = strComputerArray(0) & "," & Return
Else
'computer not online
Wscript.Echo strComputerArray(0) & ",not online"
strValue = strComputerArray(0) & ",not online"
End If
'write to output
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("C:\renameresults.txt", 8, True)
file.Write strValue & vbCrLf
file.close
Loop
objTextFile.Close
wscript.echo "Done"
wscript.quit
Function Ping(Target)
Dim results
Set shell = CreateObject("WScript.Shell")
' Send 1 echo request, waiting 2 seconds for result
Set exec = shell.Exec("ping -n 1 -w 2000 " & Target)
results = LCase(exec.StdOut.ReadAll)
Ping = (InStr(results, "reply from") > 0)
End Function