我们有一个脚本,可以自动将新映像的计算机添加到域中。 join域的function总是成功的。 但是,当脚本尝试添加域组时,它会在50%的时间内失败。 以下是脚本。 我没有写,我只是要弄清楚为什么它失败了。 我replace了公司识别信息。 有任何想法吗?
On Error Resume Next Const HKEY_LOCAL_MACHINE = &H80000002 Dim WShell, oReg Dim intReturn Dim strComputer, strKeyPath, strPortConf, strValue, strTempDir, strUser, strChassis, strPath Dim strDomain, strDomainUser, strDomainPW, strDomainOU Dim booDesktop, booLaptop Dim strPCName, objWMIService strDomain = "ourDomain.com" strDomainUser = "serviceaccountname" strDomainPW = "serviceaccountpassword" strDomainOU = "OU=Production,OU=General Workstations,DC=SOMETHING,DC=GOES,DC=HERE,DC=COM" booLaptop = False booDesktop = False Set WShell = Wscript.CreateObject("Wscript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") strComputer = "." strUser = "" strPath = "" strTempDir = "" strPath = GetPath(wscript.scriptfullname) strTempDir = "C:\Windows\IT\scripts" If right(strPath,1) <> "\" Then strPath = strPath + "\" End if Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") '------------ ' Start code '------------ Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colChassis = objWMIService.ExecQuery _ ("Select * from Win32_SystemEnclosure",,16) For Each objChassis in colChassis For Each objItem in objChassis.ChassisTypes Select Case objItem Case 1 booDesktop = True 'Maybe Virtual Machine Case 2 strChassis = "??" Case 3 booDesktop = True Case 4 booDesktop = True Case 5 strChassis = "Pizza Box" Case 6 booDesktop = True Case 7 booDesktop = True Case 8 booLaptop = True 'Portable Case 9 booLaptop = True 'Laptop Case 10 booLaptop = True 'Notebook Case 11 strChassis = "Hand Held" Case 12 strChassis = "Docking Station" Case 13 strChassis = "All in One" Case 14 strChassis = "Sub Notebook" Case 15 booDesktop = True 'Space-Saving, SFF - Our standard desktop Case 16 strChassis = "Lunch Box" Case 17 strChassis = "Main System Chassis" Case 18 strChassis = "Lunch Box" Case 19 strChassis = "SubChassis" Case 20 strChassis = "Bus Expansion Chassis" Case 21 strChassis = "Peripheral Chassis" Case 22 strChassis = "Storage Chassis" Case 23 strChassis = "Rack Mount Unit" Case 24 strChassis = "Sealed-Case PC" End Select Next Next 'Add the machine into the domain if it is a Desktop or a Laptop If booLaptop Then strDomainOU = "OU=Back Office,OU=Laptops," + strDomainOU If booDesktop Then strDomainOU = "OU=Back Office,OU=Desktops," + strDomainOU Set domFile = fs.CreateTextFile( strTempDir + "\dominfo.xml" ) domFile.WriteLine "<?xml version=""1.0"" encoding=""UTF-8""?>" domFile.WriteLine "<configuration>" domFile.WriteLine " <DOMAIN>" + strDomain + "</DOMAIN>" domFile.WriteLine " <USERID>" + strDomainUser + "</USERID>" domFile.WriteLine " <PASSWORD>" + strDomainPW + "</PASSWORD>" domFile.WriteLine " <OUTOJOIN>" + strDomainOU + "</OUTOJOIN>" domFile.WriteLine "</configuration>" domFile.WriteLine() domFile.Close() 'Join the Workstation to the Domain intReturn = WShell.Run(strTempDir + "\jdom /F " + strTempDir + "\dominfo.xml",0, true) strKeyPath = "SOFTWARE\Novell\Login\TAB SETTINGS\NT Credentials" oReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, "Sync NDS Username", "1" 'Delay the remainder of the script for 30000 milliseconds (30 seconds). WScript.Sleep(30000) 'Add the Back Office Admins group to the local administrators group WShell.Run strTempDir + "\jdom /A ""Back Office - Local Admins"" ""Group"" ",0, true 'Add the Back Office Power Users group to the local Power Users group WShell.Run strTempDir + "\jdom /P ""Back Office - Power Users"" ""Group"" ",0, true '********************* '* Main Join Script * '* (END) * '* ----------------- * Function GetPath(ByVal gpFileName) on error resume next Dim gpSlash, gpLast If IsEmpty(gpFileName) Then GetPath = "" Else gpSlash = InStr(gpFileName, "\") gpLast = gpSlash Do While gpSlash <> 0 gpSlash = InStr(gpSlash + 1, gpFileName, "\") If gpSlash > 0 Then gpLast = gpSlash End If Loop if gpLast = InStr(gpFileName, "\") then gpLast = gpLast + 1 GetPath = Left(gpFileName, gpLast - 1) End If on error goto 0 End Function
这可能是说,wscript.sleep(30000)。 我敢打赌,失败的时候是因为脚本在计算机被添加到域之前恢复执行。 一个明显的补丁/testing将等待时间增加到一分钟左右,但不是最佳的。 也许像zeda在评论中提出的是更好的解决scheme。 尽pipe如此,等待时间应该是一个补丁
我们拿出了小组的补充,并采取了组策略。 我们发现通过脚本添加的组的问题是域控制器中的延迟。 直到可以解决的时候,除了集体政策之外,没有其他的解决办法,本来应该是这样的。