Introduction - Creating new a new Contact with WSHThis 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
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:
Set objUser = objOU.Create("contact", "cn=SalesMan")
- Copy the entire Script in the green box below.
- Paste it into notepad.exe.
- File (menu), Save as SalesMan.vbs. Note: This is where people go
wrong, remember the .vbs extension.
- Double click SalesMan.vbs
- 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. If you get an error message -
check this page See Also
|