"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
--