Create Groups 
Author Message
 Create Groups

I want to create around 100 "Local Domain Groups" I have a text file
that has the group names in it and I could use DOS and the net
localgroup command but this doesn't put the groups in the correct
place in the Active Directory. I think I need to use LDAP for that.
Any help would be appreciated.

Thanks
Simon



Wed, 17 Aug 2005 17:01:43 GMT  
 Create Groups

Quote:

>I want to create around 100 "Local Domain Groups" I have
a text file
>that has the group names in it and I could use DOS and
the net
>localgroup command but this doesn't put the groups in the
correct
>place in the Active Directory. I think I need to use LDAP
for that.
>Any help would be appreciated.

>Thanks
>Simon
>.

Hi,

You can use the FileSystemObject to read group names from
a text file. You would bind to the container with the LDAP
provider and invoke the Create method. Here is a VBScript
program I modified from one I used. It is designed to be
run at a command prompt with the cscript host. I pass the
name of the file with the group names as an argument to
the program. However, I hard coded the AD container where
the groups are created.

Option Explicit
Dim objFSO, strFileName, strContainerDN, objFile
Dim objContainer, objGroup, strGroupName, intCount

Const GROUP_TYPE_BUILTIN = &H00000001
Const GROUP_TYPE_GLOBAL = &H00000002
Const GROUP_TYPE_LOCAL = &H00000004
Const GROUP_TYPE_UNIVERSAL = &H00000008
Const GROUP_TYPE_SECURITY = &H80000000

If Wscript.Arguments.Count <> 1 Then
  Wscript.Echo "Syntax error"
  Wscript.Echo _
"cscript //nologo CreateGroups.vbs c:\MyFolder\Groups.txt"
  Wscript.Quit
End If

strContainerDN = "ou=Sales,dc=MyDomain,dc=com"
strFileName = Wscript.Arguments(0)

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
Err.Clear
Set objFile = objFSO.OpenTextFile(strFileName, 1)
If Err.Number <> 0 Then
  Err.Clear
  Wscript.Echo "File not found: " & strFileName
  Wscript.Quit
End If

Err.Clear
Set objContainer = GetObject("LDAP://" & strContainerDN)
If Err.Number <> 0 Then
  Err.Clear
  Wscript.Echo "Container not found: " & strContainerDN
  Wscript.Quit
End If
On Error GoTo 0

intCount = 0
Do Until objFile.AtEndOfStream
  strGroupName = objFile.ReadLine
  If strGroupName <> "" Then
    Set objGroup = objContainer.Create("group", _
      "cn=" & strGroupName)
    objGroup.Put "sAMAccountName", strGroupName
    objGroup.Put "groupType", GROUP_TYPE_LOCAL _
      Or GROUP_TYPE_SECURITY
    On Error Resume Next
    Err.Clear
    objGroup.SetInfo
    If Err.Number <> 0 Then
      Err.Clear
      Wscript.Echo "Unable to create group " & strGroupName
    Else
      intCount = intCount + 1
    End If
    On Error GoTo 0
  End If
Loop

Wscript.Echo "Done, " & intCount & " groups created"

You could also pass the container distinguished name to
the program as an argument. Or, the text file could have
both the group name and the container distinguishedName on
each line. In that case the program would have to parse
each line to extract the group name and container DN. Note
that I "Or" the constants for "Local" and "Security"
groups. Without the "Security" flag, the group is a
distribution list. You can easily adapt for other types of
groups by using the other constants defined. The
sAMAccountName attribute is required, but always has the
same value as the cn attribute.

Richard



Thu, 18 Aug 2005 02:04:20 GMT  
 Create Groups
Thanks Richard,
I'll try that.

On Sat, 1 Mar 2003 10:04:20 -0800, "Richard Mueller"

Quote:


>>I want to create around 100 "Local Domain Groups" I have
>a text file
>>that has the group names in it and I could use DOS and
>the net
>>localgroup command but this doesn't put the groups in the
>correct
>>place in the Active Directory. I think I need to use LDAP
>for that.
>>Any help would be appreciated.

>>Thanks
>>Simon
>>.
>Hi,

>You can use the FileSystemObject to read group names from
>a text file. You would bind to the container with the LDAP
>provider and invoke the Create method. Here is a VBScript
>program I modified from one I used. It is designed to be
>run at a command prompt with the cscript host. I pass the
>name of the file with the group names as an argument to
>the program. However, I hard coded the AD container where
>the groups are created.

>Option Explicit
>Dim objFSO, strFileName, strContainerDN, objFile
>Dim objContainer, objGroup, strGroupName, intCount

>Const GROUP_TYPE_BUILTIN = &H00000001
>Const GROUP_TYPE_GLOBAL = &H00000002
>Const GROUP_TYPE_LOCAL = &H00000004
>Const GROUP_TYPE_UNIVERSAL = &H00000008
>Const GROUP_TYPE_SECURITY = &H80000000

>If Wscript.Arguments.Count <> 1 Then
>  Wscript.Echo "Syntax error"
>  Wscript.Echo _
>"cscript //nologo CreateGroups.vbs c:\MyFolder\Groups.txt"
>  Wscript.Quit
>End If

>strContainerDN = "ou=Sales,dc=MyDomain,dc=com"
>strFileName = Wscript.Arguments(0)

>Set objFSO = CreateObject("Scripting.FileSystemObject")

>On Error Resume Next
>Err.Clear
>Set objFile = objFSO.OpenTextFile(strFileName, 1)
>If Err.Number <> 0 Then
>  Err.Clear
>  Wscript.Echo "File not found: " & strFileName
>  Wscript.Quit
>End If

>Err.Clear
>Set objContainer = GetObject("LDAP://" & strContainerDN)
>If Err.Number <> 0 Then
>  Err.Clear
>  Wscript.Echo "Container not found: " & strContainerDN
>  Wscript.Quit
>End If
>On Error GoTo 0

>intCount = 0
>Do Until objFile.AtEndOfStream
>  strGroupName = objFile.ReadLine
>  If strGroupName <> "" Then
>    Set objGroup = objContainer.Create("group", _
>      "cn=" & strGroupName)
>    objGroup.Put "sAMAccountName", strGroupName
>    objGroup.Put "groupType", GROUP_TYPE_LOCAL _
>      Or GROUP_TYPE_SECURITY
>    On Error Resume Next
>    Err.Clear
>    objGroup.SetInfo
>    If Err.Number <> 0 Then
>      Err.Clear
>      Wscript.Echo "Unable to create group " & strGroupName
>    Else
>      intCount = intCount + 1
>    End If
>    On Error GoTo 0
>  End If
>Loop

>Wscript.Echo "Done, " & intCount & " groups created"

>You could also pass the container distinguished name to
>the program as an argument. Or, the text file could have
>both the group name and the container distinguishedName on
>each line. In that case the program would have to parse
>each line to extract the group name and container DN. Note
>that I "Or" the constants for "Local" and "Security"
>groups. Without the "Security" flag, the group is a
>distribution list. You can easily adapt for other types of
>groups by using the other constants defined. The
>sAMAccountName attribute is required, but always has the
>same value as the cn attribute.

>Richard



Fri, 19 Aug 2005 03:11:52 GMT  
 Create Groups
Check out the MS Scriptcenter.  They have many prebuilt scripts for creating
users and groups.

http://www.microsoft.com/technet/treeview/default.asp?url=/technet/sc...
ter/default.asp

Charles


Quote:
> Thanks Richard,
> I'll try that.

> On Sat, 1 Mar 2003 10:04:20 -0800, "Richard Mueller"


> >>I want to create around 100 "Local Domain Groups" I have
> >a text file
> >>that has the group names in it and I could use DOS and
> >the net
> >>localgroup command but this doesn't put the groups in the
> >correct
> >>place in the Active Directory. I think I need to use LDAP
> >for that.
> >>Any help would be appreciated.

> >>Thanks
> >>Simon
> >>.
> >Hi,

> >You can use the FileSystemObject to read group names from
> >a text file. You would bind to the container with the LDAP
> >provider and invoke the Create method. Here is a VBScript
> >program I modified from one I used. It is designed to be
> >run at a command prompt with the cscript host. I pass the
> >name of the file with the group names as an argument to
> >the program. However, I hard coded the AD container where
> >the groups are created.

> >Option Explicit
> >Dim objFSO, strFileName, strContainerDN, objFile
> >Dim objContainer, objGroup, strGroupName, intCount

> >Const GROUP_TYPE_BUILTIN = &H00000001
> >Const GROUP_TYPE_GLOBAL = &H00000002
> >Const GROUP_TYPE_LOCAL = &H00000004
> >Const GROUP_TYPE_UNIVERSAL = &H00000008
> >Const GROUP_TYPE_SECURITY = &H80000000

> >If Wscript.Arguments.Count <> 1 Then
> >  Wscript.Echo "Syntax error"
> >  Wscript.Echo _
> >"cscript //nologo CreateGroups.vbs c:\MyFolder\Groups.txt"
> >  Wscript.Quit
> >End If

> >strContainerDN = "ou=Sales,dc=MyDomain,dc=com"
> >strFileName = Wscript.Arguments(0)

> >Set objFSO = CreateObject("Scripting.FileSystemObject")

> >On Error Resume Next
> >Err.Clear
> >Set objFile = objFSO.OpenTextFile(strFileName, 1)
> >If Err.Number <> 0 Then
> >  Err.Clear
> >  Wscript.Echo "File not found: " & strFileName
> >  Wscript.Quit
> >End If

> >Err.Clear
> >Set objContainer = GetObject("LDAP://" & strContainerDN)
> >If Err.Number <> 0 Then
> >  Err.Clear
> >  Wscript.Echo "Container not found: " & strContainerDN
> >  Wscript.Quit
> >End If
> >On Error GoTo 0

> >intCount = 0
> >Do Until objFile.AtEndOfStream
> >  strGroupName = objFile.ReadLine
> >  If strGroupName <> "" Then
> >    Set objGroup = objContainer.Create("group", _
> >      "cn=" & strGroupName)
> >    objGroup.Put "sAMAccountName", strGroupName
> >    objGroup.Put "groupType", GROUP_TYPE_LOCAL _
> >      Or GROUP_TYPE_SECURITY
> >    On Error Resume Next
> >    Err.Clear
> >    objGroup.SetInfo
> >    If Err.Number <> 0 Then
> >      Err.Clear
> >      Wscript.Echo "Unable to create group " & strGroupName
> >    Else
> >      intCount = intCount + 1
> >    End If
> >    On Error GoTo 0
> >  End If
> >Loop

> >Wscript.Echo "Done, " & intCount & " groups created"

> >You could also pass the container distinguished name to
> >the program as an argument. Or, the text file could have
> >both the group name and the container distinguishedName on
> >each line. In that case the program would have to parse
> >each line to extract the group name and container DN. Note
> >that I "Or" the constants for "Local" and "Security"
> >groups. Without the "Security" flag, the group is a
> >distribution list. You can easily adapt for other types of
> >groups by using the other constants defined. The
> >sAMAccountName attribute is required, but always has the
> >same value as the cn attribute.

> >Richard



Sat, 20 Aug 2005 07:33:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Create Group in AD

2. create group

3. how to programtically create GROUPS?

4. How do I create a Group using ADSI?

5. Creating Windows2000 groups with VBS

6. W2000: Create Security-Group in ActiveDirectory

7. creating a group policy object?

8. Creating Local Group on Server

9. How to create dialog box with option group

10. How to create a machine group and permissions in W2K

11. W2000: Create Security-Group in ActiveDirectory

12. create a local group (nt 4.0) ??

 

 
Powered by phpBB® Forum Software