TheTAZZone - Internet Chaos

Script for a company migrating 2 domains into 1

ORIGINALLY POSTED BY CEMETRIC FOR THETAZZONE/TAZFORUM HERE

NOT ALL THE CODE MAY BE IN THIS POST…PLEASE FOLLOW THE LINK TO THE ORIGINAL THREAD

I’ve created following script for a company migrating 2 domains into 1.
It’s a simple script, but it’s so nice to use (since I created it myself :mrgreen: ) I thought I’d post it in here. Besides it might be usefull for me again some day.

The vbscript will automatically migrate computers from one domain to another with 1 reboot. This means, take em off the one domain, move them on the other.

When run, the script will give you a pop-up box where you’ll need to fill in the name of a txt file wherein you have a list of computer names (1 computer/line). The script will then loop through the list, ping every computer to see if it’s online, if it’s online it will then do it’s thing. If the pc is not online, it will place the name of the pc into a logfile mentioning it wasn’t online.

The script uses NETDOM to switch the pc to the new domain. (NETDOM can be found in the support tools of XP for example).

Tested on Windows 2000 pro and Windows XP Pro
————————————————————————————-

Code: Select all
'###############################################
'Script created: 15/02/2007
'Created by: cemetric
'Purpose: Migrate Computer resources to new domain.
'Howto: When the script is run, you'll need to input
'the txt file with the computer names, each computer
'on a seperate line.
'###############################################

On Error Resume Next

Set oFSO = CreateObject(“Scripting.FileSystemObject”)
set WSHShell = wscript.createObject(“wscript.shell”)
Set objShell = CreateObject(“WScript.Shell”)

title = “Choose file to start migration”
message = “Please enter the name of the text file (eg: comp.txt). Leave blank or press cancel to quit.” & vbCrLf & vbCrLf & generatedName

OffList = InputBox(message, title)

Set oTextStream = oFSO.OpenTextFile(OffList)

RemotePC = Split(oTextStream.ReadAll, vbNewLine)

oTextStream.Close

For Each strWorkstation In RemotePC

strCommand = “%comspec% /c ping -n 3 -w 1000 ” & strWorkstation & “”
Set objExecObject = objShell.Exec(strCommand)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, “Reply”) > 0 Then

Call WSHShell.Run(“cmd.exe /c NETDOM REMOVE “_
& strWorkstation &” _
/Domain:currdomainname /UserD:admin /PasswordD:pass _ /UserO:administrator /PasswordO:pass”)

Wscript.sleep 15000

Call WSHShell.Run(“cmd.exe /c NETDOM JOIN “_
& strWorkstation &”_
/Domain:newdomainname /UserD:Administrator /PasswordD:pass_
/UserO:administrator /PasswordO:pass /REBoot:0”)

Else
Set NokFile = oFSO.CreateTextFile(“c:\wrkstlog.txt”, True)
NokFile.WriteLine( “PC ” & strWorkstation & ” Was not online”)

End If

Loop

Next

Wscript.Echo ”                Finished”

The NETDOM lines in the script were truncated by the inputbox of this site, remember to put them on 1 line or use the (_) underscores to shorten text.

The script might not work if you just copy it and try to run it, you’ll need to adjust above mentioned lines. Also, if you have a problem with this script, ask for help in the answer thread, so this thread stays clean.

Thnx,

=C=

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertise

If you'd like to advertise on The Mutt ( aka TheTAZZone.com ) feel free to contact us at: administration[at]thetazzone.com

TheTAZZone is a non-commercial entity. We do not sell any products or services ourselves. Our revenue comes from advertising and donations only.

We appreciate your support! Your advertising revenue ( or donations ) helps us to continue to upgrade, improve, and offset the costs of maintaining this site.

Donations can be made through the page ' Donate '.