Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

How to add Domain Users to Group in Active Directory through vbscript

In order to add domain user to domain group first get the group object then get the domain user from active directory, then add user's ADsPath to group as shown in below sample code.
 
Set objGroup = GetObject("LDAP://CN=TestGroup,OU=TestOU,DC=TEST,DC=com")
Set objUser = GetObject("LDAP://CN=TestUser,OU=TestOU,DC=TEST,DC=com")
objGroup.Add(objUser.ADsPath)
Wscript.echo "Successfully added user TestUser to TestGroup"

How to set password for users in Active Directory through vbscript



Below is the sample vbscript to set password for Users in Active Directory

'First connect to container (OU) under which we will create user
TempUserName="TempUser"
Set objUser = GetObject("LDAP://cn=TempUserName,OU=TestOU,DC=TEST,DC=COM")

objUser.SetPassword "Testme123"
'Also set password never expires
objUser.Put "PasswordExpired", CLng(1)
objUser.SetInfo

Wscript.echo "Sucessfully Set password for user TempUser"


Code above connects to the active directory object with CN=TempUser, ( connects to user TempUser) under TestOU, domain Test.com. The SetPassword will set the provided password for user and additionally we can set Password Never expires flag for that user.  

How to enable user account in Active Directory through vbscript

Below is the sample vbscript to enable the user from Active Directory

Set objOU = GetObject("LDAP://TestDC/OU=TestUO,DC=Test,DC=com")
Set objUser = GetObject("LDAP://CN=TempUser,OU=TestOU,DC=Test,DC=com")
objUser.AccountDisabled = FALSE
objUser.SetInfo
Wscript.echo "Successfully enabled TempUser from Test.Com"

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

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)

Caching is a technique used to store frequently accessed data in a temporary storage layer to improve system performance and reduce latency....