Scripting - Sample Users/Group creation in AD
Set oRoot = GetObject("LDAP://rootDSE")
Set oDomain = GetObject("LDAP://" & oRoot.Get("defaultNamingContext"))
Set oOU=oDomain.Create("organizationalUnit", "ou=My Corp Users")
oOU.SetInfo
Set oUser = oOU.Create("User", "cn=Director One")
oUser.Put "sAMAccountName", "director1"
oUser.SetInfo
oUser.givenName="Director One"
oUser.displayName="Director One"
oUser.title="Managing Director"
oUser.department="Director Dept"
oUser.mail="director1@mycompany.com.vn"
oUser.employeeID=789
SetCommonProps(oUser)
Set oUser = oOU.Create("User", "cn=Manager One")
oUser.Put "sAMAccountName", "manager1"
oUser.SetInfo
oUser.givenName="Manager One"
oUser.displayName="Manager One"
oUser.title="Sales Manager"
oUser.department="Sales & Marketing Dept"
oUser.mail="manager1@mycompany.com.vn"
oUser.employeeID=678
oUser.manager="CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
SetCommonProps(oUser)
Set oUser = oOU.Create("User", "cn=Staff One")
oUser.Put "sAMAccountName", "staff1"
oUser.SetInfo
oUser.givenName="Staff One"
oUser.displayName="Staff One"
oUser.title="Sales Executive"
oUser.department="Sales & Marketing Dept"
oUser.mail="staff1@mycompany.com.vn"
oUser.employeeID=123
oUser.manager="CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
SetCommonProps(oUser)
Set oUser = oOU.Create("User", "cn=Staff Two")
oUser.Put "sAMAccountName", "staff2"
oUser.SetInfo
oUser.givenName="Staff Two"
oUser.displayName="Staff Two"
oUser.title="Cashier"
oUser.department="Sales & Marketing Dept"
oUser.mail="staff2@mycompany.com.vn"
oUser.employeeID=234
oUser.manager="CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
SetCommonProps(oUser)
Set oUser = GetObject("LDAP://CN=Administrator,CN=Users,DC=mycompany,DC=com,DC=vn")
oUser.givenName="Administrator"
oUser.displayName="Administrator"
oUser.title="System Admin"
oUser.department="Director Dept"
oUser.mail="administrator@mycompany.com.vn"
oUser.employeeID=012
oUser.manager="CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
oUser.SetInfo
SetCommonProps(oUser)
Set oGroup = oOU.Create("Group", "cn=Directors") 'Global group creation
oGroup.Put "sAMAccountName", "Directors"
oGroup.SetInfo
oGroup.member="CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
oGroup.SetInfo
Set oGroup = oOU.Create("Group", "cn=Chief Accountants")
oGroup.Put "sAMAccountName", "ChiefAccountants"
oGroup.SetInfo
oGroup.member="CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
oGroup.SetInfo
Set oGroup = oOU.Create("Group", "cn=Accountants") 'Global group creation
oGroup.Put "sAMAccountName", "Accountants"
oGroup.SetInfo
oGroup.member="CN=Staff One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn"
oGroup.SetInfo
Wscript.Echo "Users/Groups Creation Successul!"
sub SetCommonProps(oUser)
oUser.SetPassword "P@ssw0rd"
oUser.AccountDisabled = False
oUser.company="My Company"
oUser.streetAddress="123 XYZ Street"
oUser.l="Hanoi"
oUser.c="VN"
oUser.telephoneNumber="+84-4-123-45678"
oUser.mobile="+84-9-1234-5678"
oUser.userAccountControl=66080 '0x10220=PASSWD_NOTREQD|NORMAL_ACCOUNT|DONT_EXPIRE_PASSWD)
oUser.SetInfo
end sub