IT tutorials
 
Technology
 

Windows Server 2008 : Manipulating Active Directory with Visual Basic Scripts (part 1)

9/30/2013 3:33:12 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

1. Connecting to Active Directory with a VB Script

When working with Active Directory, the first step is to connect the instance of Active Directory. The basic syntax to connect with a Visual Basic (VB) script is

set objdom =getobject("LDAP://dn")

Note

LDAP, which is an acronym for Lightweight Directory Access Protocol, must be in all capital letters.


For example, to connect to the pearson.pub domain, the dn is “dc=pearson,dc=pub”, so the syntax is

set objdom = getobject("LDAP://dc=pearson,dc=pub")

2. Creating an OU with a VB Script

The following script creates an OU named Project Team:

set objdom = getobject("LDAP://dc=pearson,dc=pub")
set objou = objdom.create("organizationalunit","ou=Project Team")
objou.setinfo

The following table explains each of these three lines.

Creating an OUComments
set objdom =
getobject("LDAP://
dc=pearson,dc=pub")

This line sets the context to the pearson.pub domain. It creates an object named objdom and uses the getobject method to connect to the pearson.pub domain.

Note

LDAP must be all uppercase.

set objou = objdom.create
("organizationalunit",
"ou=Project Team")

This command uses the create method of the objdom object to create an OU named Project Team. However, the OU isn’t created yet.

Note

The case of Project Team can be uppercase, lowercase, or any combination. However, it is displayed the way it’s included in this line.

objou.setinfoThe setinfo method creates the previously defined OU.

You can use the following steps to create this script.

StepAction
1.Start a command prompt.
2.Type the following text, and then press Enter:
notepad c:\scripts\createou.vbs

3.When prompted to create the file, click Yes.
4.Add the following three lines to the script:
set objdom = getobject("LDAP://dc=pearson,dc=pub")
set objou = objdom.create("organizationalunit","ou=Project Team")
objou.setinfo

5.Press Ctrl+S to save the script.
6.Return to the command prompt, type the following text, and then press Enter:
Cscript c:\scripts\createou.vbs

7.Launch Active Directory Users and Computers from the Administrative Tools menu and you’ll see the Project Team OU created.

3. Creating a User Account with a VB Script

The following script creates a user named Jackie in the Project Team OU:

set objOU = getobject("LDAP://ou=project team,dc=pearson,dc=pub")
set objuser = objou.create("user", "cn=Jackie")
objuser.put "samaccountname", "Jackie"
objuser.setinfo

The following table explains each of these lines.

Creating an OUComments
set objOU =
getobject("LDAP://
ou=project
team,dc=pearson,dc=pub")

This line sets the context to the pearson.pub domain. It creates an object named objdom and uses the getobject method to connect to the pearson.pub domain.

Note

LDAP must be all uppercase.

set objuser = objou.
create("user", "cn=Jackie")

This command uses the create method of the objdom object to create a user named Jackie. However, the user isn’t created yet.

Note

The case of Jackie can be uppercase, lowercase, or any combination. However, it will be displayed the way it’s included in this line.

objuser.put "samaccountname", "Jackie"You can assign values to any properties with the put method of the user object. This line sets the value of the samaccountname property to Jackie.
objou.setinfoThe setinfo method creates the previously defined user.
 
Others
 
- InfoPath with SharePoint 2010 : Enhancing the User Experience - Use Pictures as Choices
- InfoPath with SharePoint 2010 : Enhancing the User Experience - Create a Tabbed Navigation in Your Form
- InfoPath with SharePoint 2010 : Enhancing the User Experience - Make Screen Tips Informative for Validation, Notify the User of Successful Submission
- InfoPath with SharePoint 2010 : Enhancing the User Experience - Configure Dynamic Sections
- InfoPath with SharePoint 2010 : Enhancing the User Experience - Display a Read-Only Value
- Windows 7 : Using a Windows Network - Sharing Resources (part 2) - Sharing Folders Independently
- Windows 7 : Using a Windows Network - Sharing Resources (part 1) - Sharing with a Homegroup
- Windows 7 : Using a Windows Network - Network Power User Topics (part 2) - Mapping Drive Letters
- Windows 7 : Using a Windows Network - Network Power User Topics (part 1) - Understanding the UNC Naming Convention
- Windows 7 : Using Printers on the Network
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us