Code:
 



Break On
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Height = 346
$Form.Left = 5
$Form.MaximizeBox = "False"
$Form.MinimizeBox = "False"
$Form.Text = "JoinDomain"
$Form.Top = 22
$Form.Width = 510
;**************************************

;************* Label1 **************
$Label1 = $Form.Controls.Label("Computer Name", 15, 120, 96, 22)
;**************************************

;************* Label5 **************
$Label5 = $Form.Controls.Label("Accounts to Add", 15, 180, 100, 23)
;**************************************

;************* Label6 **************
$Label6 = $Form.Controls.Label("Add to which OU", 15, 150, 100, 23)
;**************************************

;************* ComputerBox **************
$ComputerBox = $Form.Controls.TextBox("@wksta", 135, 120, 355, 20)
;**************************************

;************* OUCombo **************
$OUCombo = $Form.Controls.ComboBox("", 135, 150, 355, 21)
$OUCombo.DropDownWidth = 355
$OUCombo.Sorted = "True"
;**************************************

;************* AccountsBox **************
$AccountsBox = $Form.Controls.TextBox("", 135, 180, 355, 20)
;**************************************

;************* StartButton **************
$StartButton = $Form.Controls.Button("Start", 15, 225, 95, 82)
$StartButton.OnClick = "StartClick()"
;**************************************

;************* StatusBox **************
$StatusBox = $Form.Controls.ListBox("ListBox1", 135, 225, 355, 82)
;**************************************

;************* DomainGroup **************
$DomainGroup = $Form.Controls.GroupBox("Connect to Domain", 15, 15, 472, 79)
;**************************************

;************* Label7 **************
$Label7 = $DomainGroup.Controls.Label("Domain", 15, 20, 98, 18)
;**************************************

;************* Label8 **************
$Label8 = $DomainGroup.Controls.Label("Domain Account", 135, 20, 99, 15)
;**************************************

;************* Label9 **************
$Label9 = $DomainGroup.Controls.Label("Domain Password", 255, 20, 98, 16)
;**************************************

;************* DomainBox **************
$DomainBox = $DomainGroup.Controls.TextBox("", 15, 45, 100, 20)
;**************************************

;************* AdminBox **************
$AdminBox = $DomainGroup.Controls.TextBox("", 135, 45, 100, 20)
;**************************************

;************* PasswordBox **************
$PasswordBox = $DomainGroup.Controls.TextBox("", 255, 45, 100, 20)
$PasswordBox.PasswordChar = "*"
;**************************************

;************* ConnectButton **************
$ConnectButton = $DomainGroup.Controls.Button("Connect", 375, 20, 85, 18)
$ConnectButton.OnClick = "VerifyDomain()"
;**************************************

;************* ConnectStatusBox **************
$ConnectStatusBox = $DomainGroup.Controls.TextBox("Not Connected", 375, 45, 83, 20)
$ConnectStatusBox.BorderStyle = 1
$ConnectStatusBox.ReadOnly = "True"
$ConnectStatusBox.TextAlign = 2
;**************************************


;KD END

;make an array of your computer OUs in $arrOUs.. LDAP format
$arrOUs =

for each $item in $arrOUs
$OUs=$item
$OUCombo.additem($OUs)
next
$DC = "domainPC"
$DomainBox.Text = "domain"
$AdminBox.Text = ""
$PasswordBox.Text = ""
$OUCombo.Enabled = "False"
$StartButton.Enabled = "False"
$AccountsBox.Enabled = "False"
$ComputerBox.Enabled = "False"


$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1


Function VerifyDomain
$objLocator = CreateObject('WbemScripting.SWbemLocator')
$objWBEM=$objLocator.ConnectServer($DC,'root\CIMV2',$DomainBox.text+'\'+$AdminBox.text,$PasswordBox.text)
if not @error
$ConnectStatusBox.Text = "Connected"
$AccountsBox.Text = 'Domain Admins, ITStaff, '+$AdminBox.Text
$ConnectButton.Enabled = "False"
$AdminBox.Enabled = "False"
$PasswordBox.Enabled = "False"
$DomainBox.Enabled = "False"
$OUCombo.Enabled = "True"
$StartButton.Enabled = "True"
$AccountsBox.Enabled = "True"
$ComputerBox.Enabled = "True"
$ComputerBox.Setfocus
endif
Endfunction


Function StartClick
$newName = $ComputerBox.text
$domain = $DomainBox.text
$password = $PasswordBox.text
$user = $AdminBox.text
$OU = $OUCombo.text
$JOINType = 1 + 2 + 32

Status("Joining")
$objNetwork = CreateObject("WScript.Network")
if not @error
$strComputer = $objNetwork.ComputerName
$objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\"+$strComputer+"\root\cimv2:Win32_ComputerSystem.Name='"+$strComputer+"'")
$ReturnValue = $objComputer.JoinDomainOrWorkGroup($Domain, $password, $Domain+"\"+$user, $OU, $JOINtype)
If $ReturnValue
Status("Failed joining "+@wksta+" to "+$domain)
Status($ReturnValue)
return
EndIf
sleep 20

Status("Renaming")
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each $objComputer in $colComputers
$err = $objComputer.Rename($NewName, $password, $Domain + "\" + $user)
If $err
Status("Failed Renaming "+@wksta+" to "+$NewName)
Status($err)
endif
Next

For Each $name In split($AccountsBox.text,',')
$name=trim($name)
Status("Adding User "+$name)
if not $name="Domain Admins"
$objGroup = GetObject('WinNT://' + @wksta + '/' + 'Administrators')
$objGroup.Add ('WinNT://'+ $domain + '/' + $name)
if @error
Status(@serror +' error adding '+$name)
EndIF
endif
Next
Status("Complete - Restart PC")
endif
endFunction


FUNCTION Status($text)
$StatusBox.additem($text)
$StatusBox.listindex=$StatusBox.listcount-1
EndFunction




Edited by Radimus (2005-01-10 03:00 PM)
_________________________
How to ask questions the smart way <-----------> Before you ask