How to create User, Computer or Group in Active Directory through vbscript

Below is the sample vbscript to create the Users in Active Directory


'First connect to container (OU) under which we will create user
Set objOU = GetObject("LDAP://TESTDC/OU=TestOU,DC=TEST,DC=COM")
username="TempUser"
Set objUser = objOU.Create("User", "cn="&username)
objUser.Put "sAMAccountName", username
objUser.Put "displayName", "Temp Name"
objUser.SetInfo
Wscript.echo "Created TempUser in Domain Test.com, having domain controller TESTDC"


Above code first connects to the container under which we are going to create user. Then we create the user with CN=TempUser, this will create user object under TestOU, domain Test.com, having domain controller TestDC. Once object is created, we have set some of the user properties such as samAccountName, displayName. SetInfo will save the modified properties of the created object.

Note: Before executing above script please make sure that the user with samaccount name TempUser does not exist in the domain and OU with name TestOU exists under Test.Com root container.

To create Computer or Group objects follow the same script except change the type of object to be created such as for computer use:
Set objComp = objOU.Create("Computer", "cn="&computername)
And for Group:
Set objGrp = objOU.Create("Group", "cn="&groupname)

No comments:

Post a Comment

Golang: Http POST Request with JSON Body example

Go standard library comes with "net/http" package which has excellent support for HTTP Client and Server.   In order to post JSON ...