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

时间:2017-04-19 07:56:36

标签: excel vbscript active-directory windows-server-2012-r2

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

  

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

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

enter image description here

这是我使用的脚本:

'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 

0 个答案:

没有答案