Windows脚本宿主错误(错误代码8007202f)

使用自定义VBScript在Windows Server 2012中的活动目录用户和计算机中创build用户时发生错误。

错误代码8007202f,发生约束违规

.vbs文件从Excel文件中检索数据。 我用脚本创build了一次用户帐号,但是当脚本第二次再次使用时,发生错误。

在这里输入图像说明

这是我使用的脚本:

 'On Error Resume Next 'Make sure to change the OU name as appropriate. Watch about the space after the name. 'Change the domain name also strOU = "OU=TempOU ," strSheet = "C:\staff.xls" 'strPWD = "12345678" ' Bind to Active Directory, Users container. Set objRootLDAP = GetObject("LDAP://rootDSE") Set objContainer = GetObject("LDAP://" & strOU & _ objRootLDAP.Get("defaultNamingContext")) ' Open the Excel spreadsheet Set objExcel = CreateObject("Excel.Application") Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 2 'Skip row for headings Do Until objExcel.Cells(intRow,1).Value = "" strCN = Trim(objExcel.Cells(intRow, 1).Value) strFirst = Trim(objExcel.Cells(intRow, 2).Value) strSam = Trim(objExcel.Cells(intRow, 3).Value) strDscpt = Trim(objExcel.Cells(intRow, 4).Value) strLast = Trim(objExcel.Cells(intRow, 5).Value) strpasswd=Trim(objExcel.Cells(intRow, 6).Value) 'strpasswd="" 'Principal Name strPrin = strSam & "@" & "NSBMTEST.com" 'New Container Name and display strCNnew = strCN 'Created container name as SMB_ Set objUser = objContainer.Create("User", "cn=" & strCNnew) objUser.userPrincipalName = strPrin objUser.sAMAccountName = strSam objUser.givenName = strFirst 'objUser.sn = strLast objUser.displayName = strCNnew objUser.Description = strDscpt objUser.SetInfo ' enable account with password objUser.userAccountControl = 512 objUser.pwdLastSet = 0 objUser.SetPassword strPWD objUser.SetPassword strpasswd objUser.SetInfo 'Pw set to not expire 'Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000 'lngFlag = objUser.userAccountControl ' lngFlag = lngFlag Or ADS_UF_DONT_EXPIRE_PASSWD 'objUser.userAccountControl = lngFlag 'objUser.SetInfo intRow = intRow + 1 Loop objExcel.Quit WScript.Quit