Jump to content

Joining Windows 7 To Server 2008 Domain


nathan2o11

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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...