title: How to set password to Active Directory account using vbscript and excel worksheet
body: <p>I've created a script that will export data from an excel worksheet and create an AD user. Everything works perfectly if I set the password inside the script; but I do not want to place the password in the script, I need it to pull the password from the worksheet. Every time i try to reference the cell that contains the password, i get the error message: Object doesn't support this property or method: 'objUser.SetPassword'   Like I said, I can pull everything else with no problem and create the entire account but cannot get pass the set password error. Line 35 is where is errors out.</p>
  
  <pre><code>' Create User Accounts Based on Information in a Spreadsheet
  Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &amp;H6
  Const ADS_ACEFLAG_OBJECT_TYPE_PRESENT = &amp;H1
  Const CHANGE_PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}"
  Const ADS_RIGHT_DS_CONTROL_ACCESS = &amp;H100
  
  Const ADS_UF_DONT_EXPIRE_PASSWD = &amp;h10000
  
  Const ADS_PROPERTY_APPEND = 3
  Const ADS_PROPERTY_DELETE = 4
  
  Set objExcel = CreateObject("Excel.Application")
  Set objWorkbook = objExcel.Workbooks.Open _
      ("C:\New_users.xlsx")
  
  intRow = 2
  
  Do Until objExcel.Cells(intRow,1).Value = ""
      Set objOU = GetObject("LDAP://ou=Share Point Users,dc=com")
      Set objUser = objOU.Create _
          ("User", "cn=" &amp; objExcel.Cells(intRow, 1).Value)
      objUser.GivenName = objExcel.Cells(intRow, 2).Value
      objUser.SN = objExcel.Cells(intRow, 3).Value
      objuser.displayName = objExcel.Cells(intRow, 4).Value
      objuser.description = objExcel.Cells(intRow, 5).Value
      objuser.mail = objExcel.Cells(intRow, 6).Value
      objuser.userprincipalName = objExcel.Cells(intRow, 7).Value
      objuser.samAccountName = objExcel.Cells(intRow, 8).Value
      objUser.SetInfo
  
      'Set Users password and enable account
      Set objUser = GetObject _
      ("LDAP://cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,dc=com")
  
      objuser.SetPassword = objExcel.Cells(intRow, 9).Value 'this where the error occurs
      objUser.AccountDisabled = False
      objuser.SetInfo
  
      ' Prevent Users From Changing Their Passwords
  
      Set objUser = GetObject _
      ("LDAP://cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,dc=com")
      Set objSD = objUser.Get("ntSecurityDescriptor")
      Set objDACL = objSD.DiscretionaryAcl
      arrTrustees = array("nt authority\self", "EVERYONE")
  
      For Each strTrustee in arrTrustees
          Set objACE = CreateObject("AccessControlEntry")
          objACE.Trustee = strTrustee
          objACE.AceFlags = 0
          objACE.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT
          objACE.Flags = ADS_ACEFLAG_OBJECT_TYPE_PRESENT
          objACE.ObjectType = CHANGE_PASSWORD_GUID
          objACE.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
          objDACL.AddAce objACE
      Next
  
      objSD.DiscretionaryAcl = objDACL
      objUser.Put "nTSecurityDescriptor", objSD
      objUser. SetInfo
  
      'Set password to never expire
  
      Set objUser = GetObject _
          ("LDAP://cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,dc=com")
      intUAC = objUser.Get("userAccountControl")
  
      If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
          Wscript.Echo "Already enabled"
      Else
          objUser.Put "userAccountControl", intUAC XOR _
              ADS_UF_DONT_EXPIRE_PASSWD
          objUser.SetInfo
          WScript.Echo "Password never expires is now enabled"
      End If
  
      ' Add a User to Domain Guest and SharepointUserOnlyGroup
      'Also sets Domain Guest as the primary group
  
      Set objGroup = GetObject _
          ("LDAP://cn=Domain Guests,cn=Users,dc=com")
      objGroup.GetInfoEx Array("primaryGroupToken"), 0
      intPrimaryGroupToken = objGroup.Get("primaryGroupToken")
  
      objGroup.PutEx ADS_PROPERTY_APPEND, _
          "member", Array("cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,dc=com")
      objGroup.SetInfo
      objUser.Put "primaryGroupID", intPrimaryGroupToken
      objUser.SetInfo
  
      Set objGroup = GetObject _
          ("LDAP://cn=SharePointOnlyGroup,ou=Groups-Security,dc=com")  
      objGroup.PutEx ADS_PROPERTY_APPEND, _
          "member", Array("cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,ou=St. Louis,ou=Sites-US,dc=stl2,dc=mddcpa,dc=com")
      objGroup.SetInfo
  
      ' Remove a User from Domain Users group
       Set objGroup = GetObject _
         ("LDAP://cn=Domain Users,cn=Users,dc=stl2,dc=mddcpa,dc=com") 
  
      objGroup.PutEx ADS_PROPERTY_DELETE, _
          "member",Array("cn=" &amp; objExcel.Cells(intRow, 1).Value &amp; ",ou=Share Point Users,dc=com")
      objGroup.SetInfo
  
  
      intRow = intRow + 1
  Loop
  
  objExcel.Quit
  </code></pre>