Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Creating Global Groups from a text file

Reply
Thread Tools Display Modes

Re: Creating Global Groups from a text file

 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-03-2009

"danthony2" <> wrote in message
news:...
>
> I have been at this for a couple of hours and just can't figure what is
> going wrong.
>
>
> Code:
> --------------------
>
>
> '================================================= =========================
> ' AUTHOR: David R
> ' DATE : 9/2/2009
>
> '================================================= =========================
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("davidtestgrlst.txt",ForReading)
>
>
> strText = objTextFile.ReadAll
>
> objTextFile.Close
>
> arrGroups = Split(strText, vbCrLf)
>
> Dim objAD, objGroup, objNewGroup, objUser, objRootDSE
> Dim objDomain, objOU
> Dim strGroup, strNewGroup, strPath, strUser
> Dim strOU, strDNSDomain
> Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
> Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
>
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("DefaultNamingContext")
> strOU ="OU=LDAPApplications,OU=Groups,"
>
> strPath ="LDAP://" & strOU & strDNSDomain
> Set objOU = GetObject(strPath)
>
> For Each strGroup in arrGroups
>
> On Error Resume Next
>
> Set objNewGroup = objOU.Create("Group", "cn="& GroupName)
> objNewGroup.Put "sAMAccountName", strGroup
> objNewGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
> ADS_GROUP_TYPE_SECURITY_ENABLED
> objNewGroup.SetInfo
>
> Next
>
>
> --------------------
>
>
> If anyone can point me to my error that would be great. The script runs
> but doesn't create the group.
>
> Thanks,
> David
>
>
> --
> danthony2
> ------------------------------------------------------------------------
> danthony2's Profile: http://forums.techarena.in/members/116955.htm
> View this thread: http://forums.techarena.in/server-scripting/1241195.htm
>
> http://forums.techarena.in
>


The variable GroupName is never assigned a value. Perhaps you intended to
use strGroup. That's the only problem I spot. However, I would recommend not
using "On Error Resume Next", as that makes troubleshooting difficult. If
you are worried that the group may already exist, and want the script to
continue in that case, then only trap errors on the "SetInfo" statement. I
believe that is where such an error would be raised. Oh, and you might also
have a blank line at the end, so maybe test for that. For example:
=====
For Each strGroup in arrGroups
If (strGroup <> "") Then
Set objNewGroup = objOU.Create("Group", "cn=" & strGroup)
objNewGroup.Put "sAMAccountName", strGroup
objNewGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
On Error Resume Next
objNewGroup.SetInfo
If (Err.Number <> 0) Then
Wscript.Echo "Unable to create group " & strGroup
Wscript.Echo "Error Number: " & Err.Number
Wscript.Echo "Description: " & Err.Description
End If
On Error GoTo 0
End If
Next
========
I also moved the "&" concatenation operator so it is clearly an operator. I
don't know if it would raise an error otherwise.

Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Global Security groups from txt file using ldifde ieden Active Directory 3 09-05-2008 06:50 PM
Creating users from a text file Kyle Winston Scripting 1 09-02-2006 03:25 AM
!URGENT!*HELP* Check File Servers ACLs for Global Groups Z_Crawford Scripting 1 10-12-2005 08:28 PM
Re: Creating Global Groups for two Domains Laura E. Hunter \(MVP\) Active Directory 1 08-18-2004 01:41 AM
Creating SAMI file with Russian Text Mike Becvar Windows Media Player 0 01-16-2004 05:44 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59