Jump to content

Joining Windows 7 To Server 2008 Domain


Recommended Posts

Hi, I am using the below script trying to join a machine to the domain. It seems to fail because I specify the OU container which the machine is to go into. If I leave it out it joins to the default Computers container fine, but the problem is I need it to go to a specific OU. It returns me an error number 2 which I googled to find out means FILE_NOT_FOUND. Any ideas folks? TIA. Const JOIN_DOMAIN = 1Const ACCT_CREATE = 2Const ACCT_DELETE = 4Const WIN9X_UPGRADE = 16Const DOMAIN_JOIN_IF_JOINED = 32Const JOIN_UNSECURE = 64Const MACHINE_PASSWORD_PASSED = 128Const DEFERRED_SPN_SET = 256Const INSTALL_INVOCATION = 262144Dim messageDim IPstrDomain = "domain"strUser = "username"strPassword = "password"strBlankOU = ""Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")strComputer = objNetwork.ComputerName Set objWMIService = GetObject ("winmgmts:" & "!\\.\root\cimv2")Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")title = "Join computer to domain"message = "Please enter computer name. Leave at default or press cancel to quit." & VbCrLf & VbCrLf & "Generated name: " & generatedNamenewComputerName = InputBox(message, title, strComputer) OU = Left(newcomputername, 7)ouString = InputBox("what ou?", ,"LDAP://OU=Teacher Laptops,OU=Laptops,OU=Clients,OU=" & OU & ",OU=Schools,DC=hbcsi,DC=internal") If newComputerName = "" Then WScript.quitEnd IfareYousure = MsgBox("Are you sure you want to add computer to domain with name:" & VbCrLf & VbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")If areYouSure = "7" Then MsgBox "Exiting script.",vbInformation Wscript.quitEnd IfSet objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:Win32_ComputerSystem.Name='" & _ strComputer & "'") ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, ouString, _ JOIN_DOMAIN + ACCT_CREATE) If ReturnValue = 0 Then MsgBox "Computer added to domain under old name without error. proceeding to change computer name. " 'shut down and restart computer after 5 seconds Dim oshell : Set oshell = CreateObject("WScript.Shell") oshell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 5"Else MsgBox "Computer not added to domain successfully. Return value: " & ReturnValueEnd If

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...