Create mail enabled group (VBScript)

This code can be found in Chapter 5 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This script was originally published in the Exchange Cookbook,
' (http://www.exchangebookcook.com). Written by Paul Robichaux, 
' Missy Koslosky, and Devin Ganger. Redistributed with permission 
' of the publisher, O'Reilly & Associates.

' This code creates a new mail-enabled group of the specified
' type. You have to specify the container and group name.

' ------ SCRIPT CONFIGURATION ------
 strDCName = "<ServerName>"	' e.g. CONT-EXBE01
 strContainer = "<containerName>" ' e.g. "/CN=Users, dc=contoso, dc=local"
 strGroupName = "<groupName>" ' e.g. "Led Zeppelin Fans" 
 Const ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = 4
 Const ADS_GROUP_TYPE_GLOBAL_GROUP       = 2
 Const ADS_GROUP_TYPE_LOCAL_GROUP        = 4
 Const ADS_GROUP_TYPE_SECURITY_ENABLED   = -2147483648
 Const ADS_GROUP_TYPE_UNIVERSAL_GROUP    = 8
' ------ END CONFIGURATION ---------

Set objContainer = GetObject("LDAP://" & strDCName & strContainer)
Set objGroup = objContainer.Create("Group", "cn=" & strGroupName)
With objGroup
  .Put "sAMAccountName", strGroupname
  .Put "groupType", ADS_GROUP_TYPE_UNIVERSAL_GROUP
  .MailEnable
  .SetInfo
End with
WScript.Echo "New group " & strGroupName & " created successfully"

This code has been viewed 2020 times.

New from the creators of TechTasks.com: StatSheet.com