WSH – Creating a New Contact

Introduction – Creating new a new Contact with WSH

This page has been superseded by two pages dealing with contacts

 ♦

Contacts are used to create email address for people outside your company.  They do not have a security account in Active Directory (which makes the script shorter).  You could create the Contact manually with Active Directory User’s and Computers.  However, there may be times when you prefer to use WSH (Windows Scripting Host) to generate new Contacts with a VBScript.

WSH Topics

Creating a new OU

Before we consider the Contact, first we need to build an OU (organizational unit) to house the Contact objects.  An advantage of having a special OU for learning about scripting is that the accounts you produce do not get mixed up with existing accounts in the Users container.  So we will call upon WSH to generate a new OU.  In my example I have called the OU MailContacts, change that name if you wish.  In WSH, the following line takes care of creating the OU:

°

Creating the Contact = SalesMan

Set objUser = objOU.Create("contact", "cn=SalesMan")

Instructions

  1. Copy the entire Script in the green box below.
  2. Paste it into notepad.exe.
  3. File (menu), Save as SalesMan.vbs.   Note: This is where people go wrong, remember the .vbs extension.
  4. Double click SalesMan.vbs
  5. Go to Active Directory Users and Computers, Press F5, observe the MailContacts OU.

 

 

‘Script to Create a new Contact account in the MailContacts OU
‘Script created by Guy Thomas
‘Feel free to adapt names

Set oRoot = GetObject("LDAP://rootDSE")
Set oDomain = GetObject("LDAP://" & oRoot.Get("defaultNamingContext"))

Set oOU=oDomain.Create("organizationalUnit", "ou=MailContacts")
oOU.Put "Description", "Guy’s Contact OU"
oOU.SetInfo

Set objOU = GetObject("LDAP://OU=MailContacts, dc=cp, dc=com")
Set objUser = objOU.Create("contact", "cn=SalesMan")
objUser.SetInfo

Wscript.Echo "Success new Contact, Check Active Directory Users and Computers – Remember F5"
 

 

Note 1: If you run the script a second time, you will need to deal with the fact that that the OU already exists.  Either ‘rem out the line (Best) or delete the OU in Active Directory.

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)

If you get an error message – check this page

See Also