Re: Error "An invalid directory pathname was passed"
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 17 May 2006 13:03:48 -0500
Hi,
You supplied good information. I believe the problem is that "CN=" is
concatenated twice in the value supplied to the Create method:
24 strNewGroupLong = "CN=" & strNewGroup
34 Set objGroup = objOU.Create("Group","cn=" & strNewGroupLong)
is equivalent to:
Set objGroup = objOU.Create("Group","cn=CN=" & strNewGroup)
I would suggest using:
Set objGroup = objOU.Create("Group","cn=" & strNewGroup)
I haven't checked the rest, but it looks good. Don't use variable
strNewGroupLong, as it is not even assigned a value in the loop. Oh, and for
efficiency, bind to objOU (the "Set objOU" statement) outside the loop
(before the "For Each" statement). This way it is only bound once.
Also, this question probably should have been posted in
microsoft.public.scripting.vbscript or microsoft.public.adsi.general, but I
found it.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"mayanman" <mayanman.27wia0@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:mayanman.27wia0@xxxxxxxxxxxxxxxxxxxxxxxx
I am trying to use a vb script to add groups to a Active Directory
Domain.
This is the first script I have tried to write, so I am new at this.
I run the script, but it errors out on line 34 with
" Script: C:\VB scripts\GlobalSecurityGroup2.vbs
" Line: 34
" Char: 1
" Error: An invalid directory pathname was passed
" Code: 80005000
" Source: Active Directory
I cannot seem to fix the error. Can someone please tell me what is
wrong with this?
1 ' VBScript to create Groups
2 ' ----------------------------------------------------------'
3 Option Explicit
4 Dim strOU, strNewGroup, strNewGroupLong, strDNSDomain, objFSO,
objTextFile
5 Dim objOU, objGroup, objRootDSE
6 Dim strGuyGp, strGPType, arrGroups
7
8 Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
9 Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000
10 Const ForReading = 1
11
12 ' Verify the OU referenced by strOU exists
13 strOU = "OU=Security Groups ,"
14
15 Set objFSO = CreateObject("Scripting.FileSystemObject")
16 Set objTextFile = objFSO.OpenTextFile _
17 ("c:\vb scripts\groups.txt", ForReading)
18
19 strNewGroup = objTextFile.ReadAll
20 objTextFile.Close
21
22 arrGroups = Split(strNewGroup, vbCrLf)
23
24 strNewGroupLong = "CN=" & strNewGroup
25
26 For Each strNewGroup in arrgroups
27
28 ' Bind to Active Directory
29 Set objRootDSE = GetObject("LDAP://RootDSE")
30 strDNSDomain = objRootDSE.Get("DefaultNamingContext")
31
32 ' Create new Group
33 Set objOU = GetObject("LDAP://" & strOU & strDNSDomain )
34 Set objGroup = objOU.Create("Group","cn=" & strNewGroupLong)
35 objGroup.Put "sAMAccountName", strNewGroup
36
37 ' Set group Type and Scope
38 objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP _
39 or ADS_GROUP_TYPE_SECURITY_ENABLED
40 objGroup.setInfo
41
42 Wscript.Echo "Created " & strNewGroup
43 Next
44
45 ' End of Global Group VBScript
Many Thanks!!
--
mayanman
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
.
- References:
- Error "An invalid directory pathname was passed"
- From: mayanman
- Error "An invalid directory pathname was passed"
- Prev by Date: Error "An invalid directory pathname was passed"
- Next by Date: Need some help please ! !
- Previous by thread: Error "An invalid directory pathname was passed"
- Next by thread: Need some help please ! !
- Index(es):
Relevant Pages
|