Hello ..
We have to change all our 200 clients to a new domain.. therfore we
have some scripts... thats ok ..but we have to change all computer
names, too.
I habe found a really good script to change a single computer account
with vbs
http://cwashington.netreach.net/depo/view.asp?Index=990&ScriptType=vbscript
it works with a Inputbox
but i would like to have a script which reads the old computername in
the first column of a .csv file and takes the new computername from
the same row but the second column.
But my script-experience isn't high enough..
I think that some other admins have similar scenarios..to manage it.
I have found this script/function to parse a line from a csv and
return a value based on the field id
http://cwashington.netreach.net/depo/view.asp?Index=958&ScriptType=vbscript
but I don't get it work together..
I hope anyone can help me
all my searches at google and groups comes to nothing
sorry for my bad english.. I'm from germany ;-)
Happy New Year 2005
Here are the scripts
-------------------------------------------------------------------------------
Dim RegKeyCompName, RegKeyTCPIP, WSHShell, ComputerName, HostName,
DomainName, FQDN, ADRootDSE, ADSysInfo, ADComputerName, ADRenameOK,
ADRNewName, vStartRenameCA, NewNAmeU, NewNameL, vStartRenameAD
On Error Resume Next
'###### READ IN EXISTING COMPUTERNAME AND FQDN ######
RegKeyCompName = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\"
RegKeyTCPIP = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\"
Set WSHShell = CreateObject("WScript.Shell")
ComputerName = WSHShell.RegRead (RegKeyCompName &
"ComputerName\ComputerName")
Hostname = WSHShell.RegRead (RegKeyTCPIP & "Hostname")
DomainName = WSHShell.RegRead (RegKeyTCPIP & "Domain")
FQDN = HostName & "." & DomainName
Set ADRootDSE = GetObject("LDAP://RootDSE")
If Err.Number <> 0 then
ADComputerName = "Unable to determine this information"
ADOU = "Unable to determine this information"
ADRenameOK = "0"
else
Set ADSysInfo = CreateObject("ADSystemInfo")
ADComputerName = ADSysInfo.ComputerName 'Get DN of
local computer
ADRenameOK = "1"
ADOU = Mid(ADComputerName, InStr(ADComputerName, "=") + 1)
'Strip off just after the first = sign
ADOU = Mid(ADOU, InStr(ADOU, "=") - 2) 'Strip off
at 2 before the second = sign
ComputerPath = "LDAP://" & ADComputerName
OUPath = "LDAP://" & ADOU
End if
'###### ASK USER FOR NEW DETAILS ###########
MsgBox "This script renames this computer and its active directory
account" & vbCr & vbCr & "Name: " & ComputerName & vbCr & "FQDN: " &
FQDN & vbCr & vbCr & "AD DN: " & ADComputerName & vbCr & "AD OU: " &
ADOU, 0, "Information"
NewName = InputBox("Enter the new computer name below and click OK to
continue","Rename: Step 1")
NewNameU = UCase(NewName)
NewNameL = LCase(NewName)
NewNameUCN = "CN=" & NewNameU
if NewName = "" then
wscript.echo "The computer name has not been changed"
else
vStartRenameCA = MsgBox ("Continue and rename computer to: " &
NewName,vbYesNo or vbExclamation,"Rename: Step 2")
if vStartRenameCA = 6 then
With WSHShell
.RegDelete RegKeyTCPIP & "Hostname"
.RegDelete RegKeyTCPIP & "NV Hostname"
.RegWrite RegKeyCompName & "ComputerName\ComputerName",
NewNameU
.RegWrite RegKeyCompName &
"ActiveComputerName\ComputerName", NewNameU
.RegWrite RegKeyTCPIP & "Hostname", NewNameL
.RegWrite RegKeyTCPIP & "NV Hostname", NewNameL
End With
wscript.echo "The computer name and FQDN have been changed"
elseif vStartRenameCA = 7 then
wscript.echo "The computer name and FQDN have NOT been
changed"
end if
if ADRenameOK = 1 then
vStartRenameAD = MsgBox ("Continue and rename AD Account to: "
& NewName,vbYesNo or vbExclamation,"Rename: Step 3")
if vStartRenameAD = 6 then
Set objItem = GetObject(ComputerPath)
objItem.Put "dNSHostName", NewNameL & DomainName
objItem.SetInfo
objItem.Put "displayName", "DESKTOP_" & NewNameU & "$"
objItem.SetInfo
objItem.Put "sAMAccountName", NewNameU & "$"
objItem.SetInfo
Set objNewOU = GetObject(OUPath)
Set objMoveComputer = objNewOU.MoveHere _
(ComputerPath, NewNameUCN)
wscript.echo "The active directory computer account has
been changed"
elseif vStartRenameAD = 7 then
wscript.echo "The computer account in AD has NOT been
changed"
End If
else
wscript.echo "Insufficient information to rename AD account"
End If
End if
------------------------------------------------------------------------
----------------------------------------------------------------------------
' Sample Usage --
TestString = "Phyisical, Data, Network, Transport, Application,
Session, Presentation"
'FYI - First data field is id=0
WScript.Echo CSV_Results(TestString, 2)
'Echoes "Network"
WScript.Echo CSV_Results(Teststring, 6)
'Echoes "Presentation"
'------
Private Function CSV_Results(csvstring, fieldID)
i = 0
Comma = Array(i)
result = Array(i)
Comma(i) = InStr(1, csvstring, ",")
result(i) = Left(csvstring, Comma(i)-1)
If InStr(1, result(i), CHR(34)) <> 0 Then
Qpos1 = InStr(1, csvstring, CHR(34))
Qpos2 = InStr(Qpos1 +1 , csvstring, CHR(34))
Comma(i) = InStr(Qpos2 +1, csvstring, ",")
result(i) = Mid(csvstring, Qpos1+1, Qpos2-Qpos1-1)
End If
Do While Comma(i) <> 0
i = i + 1
ReDim Preserve Comma(i)
ReDim Preserve result(i)
Comma(i) = InStr(Comma(i-1)+1, csvstring, ",")
If Comma(i) <> 0 Then
result(i) = Mid(csvstring, Comma(i-1)+1, Comma(i) -
Comma(i-1) -1 )
If InStr(1, result(i), CHR(34)) <> 0 Then
Qpos1 = InStr(Comma(i-1), csvstring, CHR(34))
Qpos2 = InStr(Qpos1 +1 , csvstring, CHR(34))
Comma(i) = InStr(Qpos2 +1, csvstring, ",")
result(i) = Mid(csvstring, Qpos1+1, Qpos2-Qpos1-1)
End If
End If
Loop
strLength = Len(csvstring)
result(i) = Right(csvstring, strLength - Comma(i-1))
If InStr(1, result(i), CHR(34)) <> 0 Then
result(i) = Replace(result(i), CHR(34), "")
End If
CSV_Results = result(FieldID)
End Function
-------------------------------------------------------------------------