Targeting VBScript to rename PCs



I am working on a project to clean up our AD environment. I am working on
three initiatives: Remove aged accounts, Move Computers to the correct OU
based on subnet, and rename all computers with predefined designation and
last 7 characters of the serial. I am not a very good scripter but I have
managed to pull off the first two. I have the script for the last one working
but not in the automated fashion I need. I can run it against an inputbox for
the target but I really need to run it against a text list of computers. So
basically I need helpwith an array that pulls from a list of targets . I have
found some info but am having trouble getting it to work.. Below is the
current functional script minus any array… My eventual plan is to have a text
box at start of the script that asks if it should prompt for single target or
run against pre set text file… any help would be appreciated.. Thank you

'On Error Resume Next

'*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
'Rename PC and domain machine account
'4/5/2006 Added WMI variable creation for new name
'Added reboot
'*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
'#####################################################
'Variables
'#####################################################

Dim sNewCname
Dim sOldCname
Dim StrUsername
Dim StrPassword
Dim StrFullSer, StrTrimmedName

sOldCname = InputBox("Enter computers current name")
StrUsername=InputBox("Enter Domain Username:")
StrPassword=Inputbox("Enter Domain User Password:")

'********************************************************
'Create Function
'********************************************************
Function Rencomp()
'#####################################################
' WMI pull serial and append to pre set name
' WMI pull serial and create new name added 4/4/06
' Trim serial to right 7 and append preset
'#####################################################

msgbox ("sOldCname: " & sOldCname)
Set objWMIService = GetObject("winmgmts:\\" & sOldCname & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Systemenclosure")
For Each objItem in colItems
StrFullSer= objItem.SerialNumber
next
'msgbox ("StrFullSer: " & StrFullSer)
StrTrimmedSer = trim (StrFullSer)
'msgbox ("StrTrimmedSer: " & StrTrimmedSer)
sTrimmedName = Right(StrTrimmedSer, 7)
'msgbox ("sTrimmedName 7 : " & sTrimmedName)
sNewCname = ("NUSEGLLU" & sTrimmedName)
'msgbox ("sNewCname Complete: " & sNewCname)
'#####################################################
'create Shell
'#####################################################
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'#####################################################
'Rename PC
' yesno to commented out after addition of array
'#####################################################
yesno = MsgBox _
(sOldCname & " will be renamed to: " & sNewCname, _
vbYesNo, "Script continue")
if yesno = 6 then
Call WSHShell.Run("cmd.exe /k NETDOM RENAMECOMPUTER " & sOldCname & "
/newname:" & sNewCname & " /userd:" & StrUsername & " /passwordD:" &
strPassword & " /force ")
'#####################################################
' Reboot PC
'#####################################################

WScript.Echo "Rebooting..."
set objWSHShell = WScript.CreateObject("WScript.Shell")
objWSHShell.LogEvent 0, "Computer renamed from: " & sOldCname & " To: " &
sNewCname
objWSHShell.Run "shutdown.exe -r -m \\" & sOldCname
else
Msgbox "Rename Aborted!"
end if
'********************************************************
end Function

rencomp



--
System Admin
.



Relevant Pages

  • Re: Remotely rename computer name and join to domain
    ... go to every single computer and rename it and wait and then ... If this is some unattended installation - why not script it and have it ... If you are joining old computers to a new domain - then why not script it so ...
    (microsoft.public.windowsxp.security_admin)
  • Re: force a script to resume before it is ready
    ... strState = "Offline" ... This is part of my FTP script that connects to multiple Computers (as ... trying to rename a file that does not exist. ...
    (microsoft.public.scripting.vbscript)
  • compiling a script
    ... How do I run the following script if I want to rename my computers in the domain? ... strValueName = "ActiveComputerName" ...
    (microsoft.public.scripting.wsh)
  • Re: Can I rename computers through AD?
    ... You cannot rename computers from the AD consoles. ... For WinXP you can use NETDOM which you can script to ... If you have Win2K, however, you cannot use netdom. ...
    (microsoft.public.win2000.active_directory)
  • Re: Finding users in local admin groups
    ... > Here is a vbscript that you can run against a remote computer that moves ... > *local* users except 'Administrator) from the Administrators group to the ... You should also add to the script logging to a file of the ... > you moved on what computers. ...
    (microsoft.public.win2000.security)