Skip to content

Instantly share code, notes, and snippets.

@MikeSel
Last active December 27, 2015 11:19
Show Gist options
  • Save MikeSel/7317381 to your computer and use it in GitHub Desktop.
Save MikeSel/7317381 to your computer and use it in GitHub Desktop.
Create 80 test accounts in AD and add to a group
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
Const ADS_PROPERTY_APPEND = 3
'Change to group name which youd like to add users to
Set objGroup = GetObject _
("LDAP://cn=GroupName,ou=OUName,dc=DomainName,dc=com")
For i = 1 To 80
'Creates a username called USERNAME1 to USERNAME80
Set objLeaf = objContainer.Create("User", "cn=USERNAME" & i)
objLeaf.Put "sAMAccountName", "USERNAME" & i
objLeaf.SetInfo
'Sets password of user
objLeaf.SetPassword "Pa55word"
Set objUser = GetObject _
("LDAP://cn=USERNAME" & i & ",cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
'Enables the user account
objUser.AccountDisabled = FALSE
objUser.SetInfo
objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
Array("cn=USERNAME" & i & ",cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
objGroup.SetInfo
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment