#75216 - 2003-05-30 02:17 AM
JoinAD KiXforms script to move computers into Active Directory
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11625
Loc: CA
This script is a KiXforms script created to help desktop support people to Move computers into the Active Directory under a specific OU container. You can easily modify the OU paths to your specific Network requirements to use in your environment.UPDATED CODE June 10, 2003 Requirements to run this script: 1. Active Directory (can run script for testing without AD) 2. KiXtart v4.x (preferred v4.21) 3. KiXforms v2.3.0 Beta 2 http://www.kixforms.com/assets/index.htm 4. NETDOM.EXE from MicrosoftNOTE NETDOM does not support NT 4 well for moving to a specific OU in Active Directory Description of Netdom.exe Syntax and Versionshttp://support.microsoft.com/default.aspx?scid=kb;en-us;329721 Obtaining the NETDOM.EXE utility from Microsoft The document - Best Practices: Active Directory Forest Recovery Download the documentation archive which contains the NETDOM.EXE utility for 2000 file version 5.2.3687.0 (Friday, September 27, 2002, 8:38:06 PM)http://www.microsoft.com/downloads/details.aspx?displaylang=en&Fam ilyID=3EDA5A79-C99B-4DF9-823C-933FEBA08CFE Here is a screen shot of how it currently looks; *** File Name: frmJoinAD.kix
; *** Date Created: 2003-05-22 15:00 PST - By Ron Lewis
; *** Comments: This script is used to MOVE 2000/XP Workstations into an
; *** Active Directory. Currently does not support a Computer RENAME but
; *** you should be able to easily add that functionality.
; *************** REVISION HISTORY ***************
; 01.04 *** 2003-06-10 18:35 PST - By Ron Lewis
; Corrected invalid error return. Added passing a parameter to function ShowResults
; 01.03 *** 2003-06-02 14:25 PST - By Ron Lewis
; Corrected invalid path for OU
; 01.02 *** 2003-05-29 15:30 PST - By Ron Lewis
; Enabled check for blank computer name
; 01.01 *** 2003-05-22 16:55 PST - By Ron Lewis
; Updated to install and run from UNC batch call
; 01.00 *** 2003-05-22 15:00 PST - By Ron Lewis
; Original Release
Break On
DIM $nul
IF @PRODUCTTYPE ="Windows XP Professional" OR @PRODUCTTYPE ="Windows 2000 Professional"
IF LocalAdmin
IF EXIST ('%WINDIR%\SYSTEM32\KIXFORMS.DLL' )
SHELL '%COMSPEC% /C %WINDIR%\SYSTEM32\regsvr32.exe %WINDIR%\SYSTEM32\KIXFORMS.DLL /U /S'
DEL ('%WINDIR%\SYSTEM32\KIXFORMS.DLL' )
ENDIF
COPY '@SCRIPTDIR\kixforms.dll' '%WINDIR%\SYSTEM32\'
SLEEP 2
SHELL '%COMSPEC% /C %WINDIR%\SYSTEM32\regsvr32.exe %WINDIR%\SYSTEM32\KIXFORMS.DLL /S'
$ScriptVersion =" v1.0"
$Form = CreateObject ("Kixtart.Form" )
$Form.Text = "Move Computer into Active Directory"
$Form.FontName = "Tahoma"
$Form.FontSize = 10
$Form.ClientSize = 640 ,480 ;370,380
$Form.BackColor = &E5A88A
$Form.FontName = "Arial"
$Form.FontSize = 8
$Form.Icon = "%WINDIR%\System32\shell32.dll;48"
$ImageList = $Form.ImageList
$ImageList.ImageSize = 32 ,32
$ImageList.Images.Add ($Form.SmallImageList.Images (12 ))
$ImageList.Images.Add ($Form.SmallImageList.Images (9 ))
$FrameBanner = $Form.PictureBox
$FrameBanner.BackColor = $Form.RGB (138 ,168 ,229 )
$FrameBanner.Height = 70
$FrameBanner.Left = 440
$FrameBanner.Top = 0
$FrameBanner.Width = 70
$FrameBanner.BorderStyle = 0
$PictureBanner = $FrameBanner.Image
$PictureBanner.Picture = "%WINDIR%\System32\shell32.dll;14"
$PictureBanner.Height = 60
$PictureBanner.Left = 2
$PictureBanner.Top = 2
$PictureBanner.Width = 60
$Form.FillStyle = 1
$Form.FillColor = &B24801
$Form.Rectangle (0 ,0 ,440 ,$Form.ClientHeight -20 )
$Form.ForeColor = &E5A88A +&151515
$Form.FontBold = True
$Form.FontSize = 10
$Form.PrintXY (5 ,10 ,"Computer:" )
$Form.PrintXY (5 ,60 ,"Domain\UserID:" )
$Form.PrintXY (5 ,110 ,"Password:" )
$Form.PrintXY (5 ,165 ,"Select OU Container:" )
$Form.PrintXY (5 ,380 ,"Status:" )
$Form.FontName = "arial"
$Form.FontSize = 20
$Form.FontItalic = True
$Form.FontBold = True
$Form.ForeColor = &E3A17A +&151515
$Form.PrintXY (517 ,17 ,"Join AD" )
$Form.ForeColor = &E3A17A -&151515
$Form.PrintXY (515 ,15 ,"Join AD" )
$Form.FontSize = 12
$Form.PrintXY (540 ,45 ,$ScriptVersion )
$Form.ForeColor = Gray
$Form.FontSize = 10
$Form.PrintXY (445 ,70 ,"Migration Script by Ron Lewis" )
$Form.ForeColor = BLACK
$Form.FontSize = 10
$Form.FontBold = False
$Form.FontItalic = False
$Form.PrintXY (445 ,110 ,"1: Enter Domain and User ID" )
$Form.PrintXY (445 ,130 ,"2: Enter password" )
$Form.PrintXY (445 ,150 ,"3: Select OU container" )
$Form.PrintXY (445 ,170 ,"4: Click Move Computer" )
$txtArea = $Form.ComboBox
$txtArea.Bounds = 3 ,185 ,348 ,150
$txtArea.Style = 1
$txtArea.DropDownWidth = 348
$OU1 ="Computers OU in FINANCE"
$OU2 ="Computers OU in GRAPHICS"
$OU3 ="Computers OU in ENTERTAINMENT"
$txtArea.AddItem ($OU1 )
$txtArea.AddItem ($OU2 )
$txtArea.AddItem ($OU3 )
$Computer = $Form.TextBox
$Computer.FontSize = 12
$Computer.Top = 30
$Computer.Left = 3
$Computer.Right = 350
$Computer.Height = 30
$Computer.BorderStyle = 4
$Computer.Text = @WKSTA
$Computer.FontName = "Courier New"
$Userid = $Form.TextBox
$Userid.FontSize = 12
$Userid.Top = 80
$Userid.Left = 3
$Userid.Right = 350
$Userid.Height = 30
$Userid.BorderStyle = 4
$Userid.Text = @DOMAIN +'\' +@USERID
$Userid.FontName = "Courier New"
$UserPass = $Form.TextBox
$UserPass.FontSize = 12
$UserPass.Top = 130
$UserPass.Left = 3
$UserPass.Right = 350
$UserPass.Height = 30
$UserPass.BorderStyle = 4
$UserPass.PasswordChar = "*"
$UserPass.Text = ""
$UserPass.FontName = "Courier New"
$Move = $Form.ToolButton
$Move.Alignment = 2
$Move.FlatStyle = 1
$Move.left = 455
$Move.top = 366
$Move.width = 85
$Move.height = 85
$Move.text = "&Move@crlfComputer"
$Move.Icon = $ImageList.Images (0 )
$Move.border = 3
$Move.ToolTip = "Moves current computer into the Active Directory"
$Move.BackColor = 212 ,208 ,200
$Move.OnClick = "Message()"
$Quit = $Form.ToolButton
$Quit.Alignment = 2
$Quit.FlatStyle = 1
$Quit.left = 540
$Quit.top = 366
$Quit.width = 85
$Quit.height = 85
$Quit.text = "E&xit"
$Quit.Icon = $ImageList.Images (1 )
$Quit.border = 3
$Quit.ToolTip = "Exits application without further prompting"
$Quit.BackColor = 212 ,208 ,200
$Quit.OnClick = "Quit()"
$Status = $Form.Label
$Status.Left = 0
$Status.Top = $Form.ClientHeight -20
$Status.Height = 20
$Status.Right = $Form.ClientWidth
$Status.BackColor = 212 ,208 ,200
$Status.Forecolor = Gray
$Status.BorderStyle = 5
$Status.Text = " Powered by Kixtart " +@KIX +" and Kixforms " +$Form.Version
Dim $StringUsername
Dim $StringPassword
$Form.Center
$Form.Show
While $Form.Visible
$ =Execute ($Form.DoEvents )
Loop
Exit 1
ELSE
$nul = MESSAGEBOX ("You must be logged on with Administrator rights to use this tool. " , "Insufficient Rights" , 16 )
EndIF
ELSE
$nul = MESSAGEBOX ("Only Windows 2000/XP supported. Please use another method to add NT 4.0 systems. " , "Unsupported OS" , 16 )
EXIT 199
ENDIF
Function Message ()
DIM $err2
IF $Computer.Text = ""
$err2 = $Form.MsgBox ("You must specify a valid Computer name before clicking Move Computer." , "Invalid Computer name" ,16 )
$Computer.Text = @WKSTA
EXIT Sub
ELSE
$Computer.Text = $Computer.Text
ENDIF
IF $Userid.Text = ""
$err2 = $Form.MsgBox ("You must specify a Domain and User ID before clicking Move Computer." , "Invalid Username" ,16 )
$Userid.Text = $StringUsername
Exit Sub
Else
$StringUsername = $Userid.Text
EndIf
If $UserPass.Text = ""
$err2 = $Form.MsgBox ("You must specify a password before clicking Move Computer." , "Invalid Password" ,16 )
$UserPass.Text = $StringPassword
Exit Sub
Else
$StringPassword = $UserPass.Text
EndIf
SelectOU
EndFunction
Function SelectOU ()
DIM $Action , $err
$Action ="MOVE"
Select
Case $txtArea.text =""
$err =$Form.MsgBox ("Please select a valid OU and try again" ,"Invalid OU Container Selected" ,16 )
Case $txtArea.text =$OU1
$MoveComp ='netdom.exe $Action @wksta /d:businessone.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businessone,ou=home,dc=company,dc=com /REBOOT'
SHELL $MoveComp
ShowResults (@ERROR ,@SERROR )
Case $txtArea.text =$OU2
$MoveComp ='netdom.exe $Action @wksta /d:businesstwo.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businesstwo,ou=home,dc=company,dc=com /REBOOT'
SHELL $MoveComp
ShowResults (@ERROR ,@SERROR )
Case $txtArea.text =$OU3
$MoveComp ='netdom.exe $Action @wksta /d:businessthree.home.company.com /ud:$StringUsername /PD:$StringPassword /ou:ou=computers,ou=businessthree,ou=home,dc=company,dc=com /REBOOT'
SHELL $MoveComp
ShowResults (@ERROR ,@SERROR )
CASE 1
$err =$Form.MsgBox ($txtArea.txt +"There was an unexpected error. Please verify all information and try again" ,"Unexpected Error" ,16 )
EndSelect
EndFunction
Function ShowResults ($ERROR ,$SERROR )
$Message = $Form.TextBox
$Message.FontSize = 10
$Message.Top = 400
$Message.Left = 3
$Message.Right = 440
$Message.Height = 50; 200
$Message.MultiLine = True
$Message.BorderStyle = 0
$Message.ScrollBars = 2
$Message.FontName = "Courier New"
$Message.Text = "Computer move result: " +$ERROR +' ' +$SERROR
EndFunction
function LocalAdmin ()
$LocalAdmin =ingroup ('@wksta\' +sidtoname ('S-1-5-32-544' ))-1 +@inwin
endfunction [ 11. June 2003, 04:24: Message edited by: NTDOC ]
Top
Moderator: Glenn Barnas , NTDOC , Arend_ , Jochen , Radimus , Allen , ShaneEP , Ruud van Velsen , Mart
1 registered
(Allen )
and 684 anonymous users online.