#131874 - 2004-12-30 02:27 PM
Re: FYI - Useful peaces of code...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
2 things...
1: it is pieces (not peace)
2: you rule
BTW.. have the code handy for moving computer to specific OU? What about renaming the computer?
|
Top
|
|
|
|
#131876 - 2004-12-30 07:39 PM
Re: FYI - Useful peaces of code...
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
|
Top
|
|
|
|
#131878 - 2005-01-07 08:32 PM
Re: FYI - Useful peaces of code...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
DO you have a way of verifying the username and password is correct prior to attempting the join?
I'm doing this: $objLocator = CreateObject('WbemScripting.SWbemLocator') $objWBEM=$objLocator.ConnectServer($DC,'root\CIMV2',$DomainBox.text+'\'+$AdminBox.text,$PasswordBox.text) if not @error
But I have to specify a PC ($DC) to connect to... is there a 'generic method?
|
Top
|
|
|
|
#131879 - 2005-01-07 09:02 PM
Re: FYI - Useful pieces of code...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
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)
|
Top
|
|
|
|
#131880 - 2005-01-10 03:07 PM
Re: FYI - Useful pieces of code...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
Top
|
|
|
|
#131882 - 2005-01-11 03:33 AM
Re: FYI - Useful pieces of code...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I used an older version of this based on netdom to do my win2k images.
The machines would run minisetup after the ghost image is installed, and minisetup would autoname and skip joining the domainso it runs unattended... after it completes and reboots with autoadminlogon, this form starts (or the older version) where it can be renamed, joined to domain and user accounts can be added to local admin
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 669 anonymous users online.
|
|
|