Last active
December 27, 2015 11:19
-
-
Save MikeSel/7317381 to your computer and use it in GitHub Desktop.
Create 80 test accounts in AD and add to a group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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