Targeting VBScript to rename PCs
- From: Akellar1 <Akellar1@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 6 Apr 2006 05:45:02 -0700
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
.
- Follow-Ups:
- Re: Targeting VBScript to rename PCs
- From: Richard Mueller
- Re: Targeting VBScript to rename PCs
- From: JTW
- Re: Targeting VBScript to rename PCs
- Prev by Date: Re: Event Viewer Settings
- Next by Date: Re: File.Move "Permission Denied" Error
- Previous by thread: Re: How to identify W2k versions?
- Next by thread: Re: Targeting VBScript to rename PCs
- Index(es):
Relevant Pages
|