'==========================================================================
'
'
' NAME: <CreateGroup.vbs>
'
' AUTHOR: Ed Wilson , MS
' DATE  : 5/8/2006
'
' COMMENT: <Uses adsi to create a Group
'1.Based upon the createOU script, uses many of same variable names
'2.Big difference is using Group as class, and need to specify Group name with cn
'3.Use the put method to put information into attributes on the group. 
'4.Additional piece of information NEED to specify is the TYPE of group to create.
'==========================================================================
Option Explicit
On Error Resume next
Dim strProvider 'defines how will talk to Active Directory 
Dim strOU ' path to where new object will be created
Dim strDomain 'name of Domain connecting to
Dim strClass ' the class of object we are creating
Dim strOUname 'name of object are creating
Dim objDomain 'holds connection to adsi
Dim objOU 'holds handle to create method
Dim intGroupType 'Controls type of group to create


strProvider = "LDAP://"
strOU = "OU=mred," 'when using is OU=mred, THE , would be required.
strDomain = "dc=nwtraders,dc=msft"
strClass = "Group"
strOUname = "CN=MyNewGroup"
intGroupType = 2 '2= distribution Group -2147483646 is security

Set objDomain = GetObject(strProvider & strOU & strDomain)
	WScript.echo strProvider & strOU & strDomain 'debug
Set objOU = objDomain.create(strClass, strOUname)
	WScript.echo strClass & "," & strOUname 'debug
	objOU.Put "SAMAccountName", funfix(strOUname)
	objOU.Put "GroupType", intGroupType
objOU.SetInfo

If Err.number = 0 Then
	WScript.Echo(strOUname & " was created")
Else If Err.number = "-2147019886" Then
	WScript.echo strOUname & " already exists"
Else 
	WScript.echo " error on the play " & Err.Number
End If
End If

Function funfix (strin)
funfix = Mid(strin,4) 'removes cn= from username
End function