Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Object doesn't support named arguments" Yes it does!! 1

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
Hi

Current script I'm working on is to return user names in the Domain Admins group.

The orignal script (which, as you'll see is by Richard L. Mueller) worked just fine. The bit that's refusing to work is the function (which I've added in from another script I have in which it DOES work!) that returns the user's full name.

The error is
[tt]P:\Scripts\GetDomainAdmins.vbs(153, 5) Microsoft VBScript runtime error: Object doesn't support named arguments: 'adoConnection.CommandText'[/tt]

Here's the code (just to clarify, the variable 'strExceptions' lists account names that ARE allowed to be in the domain admins group, so if a user name in the Domain Admins group isn't in this list, the script should return the username with that account's Full Name and it's the return of the full name that is failing at
Code:
adoConnection.CommandText = "<LDAP://" & strDNSDomain & _">;(&(objectCategory=User)(samAccountName=" & strLN & "));displayName;subtree"
within the ReturnDisplayName(strLN) function).
Code:
' VBScript program to document members of a group.
' Reveals nested group and primary group membership.
'
' ----------------------------------------------------------------------
' Copyright (c) 2002 Richard L. Mueller
' Hilltop Lab web site - [URL unfurl="true"]http://www.rlmueller.net[/URL]
' Version 1.0 - December 10, 2002
' Version 1.1 - January 24, 2003 - Include users whose Primary Group is
'                                  any nested group.
' Version 1.2 - February 19, 2003 - Standardize Hungarian notation.
' Version 1.3 - March 11, 2003 - Remove SearchScope property.
' Version 1.4 - April 30, 2003 - Use GetInfoEx to retrieve group
'                                primaryGroupToken.
' Version 1.5 - January 25, 2004 - Modify error trapping.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

Option Explicit

Dim objGroup, strDN, objMemberList
Dim adoConnection, adoCommand, objRootDSE, strDNSDomain
Dim strUserDisplayName
Const strExceptions = "arcserveit,doe_j_admin,administrator,"

' Dictionary object to track group membership.
Set objMemberList = CreateObject("Scripting.Dictionary")
objMemberList.CompareMode = vbTextCompare

' Check for required argument.
' Except I'm removing it because I'm hard-coding this to Domain Admins
'If (Wscript.Arguments.Count < 1) Then
'    Wscript.Echo "Required argument <Distinguished Name> " _
'        & "of group missing."
'    Wscript.Echo "For example:" & vbCrLf _
'        & "cscript //nologo EnumGroup.vbs " _
'        & """cn=Test Group,ou=Sales,dc=MyDomain,dc=com"""
'    Wscript.Quit(0)
'End If

' Bind to the group object with the LDAP provider.
'strDN = Wscript.Arguments(0)
'strDN = """CN=Domain Admins,CN=Users,DC=OurDomain,DC=com"""
strDN = "CN=Domain Admins,CN=Users,DC=OurDomain,DC=com"

On Error Resume Next
Set objGroup = GetObject("LDAP://" & strDN)
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Group " & strDN & " not found" ' & vbCrLf & strDN
    Wscript.Quit(1)
End If
On Error GoTo 0

' Retrieve DNS domain name from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Setup ADO.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Enumerate group membership.
Wscript.Echo "Members of group " & objGroup.sAMAccountName
Call EnumGroup(objGroup, "  ")

' Clean Up.
adoConnection.Close
Set objGroup = Nothing
Set objRootDSE = Nothing
Set adoCommand = Nothing
Set adoConnection = Nothing

Sub EnumGroup(ByVal objADGroup, ByVal strOffset)
    ' Recursive subroutine to enumerate group membership.
    ' objMemberList is a dictionary object with global scope.
    ' objADGroup is a group object bound with the LDAP provider.
    ' This subroutine outputs a list of group members, one member
    ' per line. Nested group members are included. Users are also
    ' included if their primary group is objADGroup. objMemberList
    ' prevents an infinite loop if nested groups are circular.

    Dim strFilter, strAttributes, adoRecordset, intGroupToken
    Dim objMember, strQuery, strNTName

    ' Retrieve "primaryGroupToken" of group.
    objADGroup.GetInfoEx Array("primaryGroupToken"), 0
    intGroupToken = objADGroup.Get("primaryGroupToken")

    ' Use ADO to search for users whose "primaryGroupID" matches the
    ' group "primaryGroupToken".
    strFilter = "(primaryGroupID=" & intGroupToken & ")"
    strAttributes = "sAMAccountName"
    strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";" _
        & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    Set adoRecordset = adoCommand.Execute
    Do Until adoRecordset.EOF
        strNTName = adoRecordset.Fields("sAMAccountName").Value
        If (objMemberList.Exists(strNTName) = False) Then
            objMemberList.Add strNTName, True
            Wscript.Echo strOffset & "'" & strNTName & "'" '& " (Primary)"
        Else
            Wscript.Echo strOffset & "'" & strNTName & "'" '& " (Primary, Duplicate)"
        End If
        adoRecordset.MoveNext
    Loop
    adoRecordset.Close

    For Each objMember In objADGroup.Members
        If (objMemberList.Exists(objMember.sAMAccountName) = False) Then
            objMemberList.Add objMember.sAMAccountName, True
            If (UCase(Left(objMember.objectCategory, 8)) = "CN=GROUP") Then
                Wscript.Echo strOffset & objMember.sAMAccountName & " (Group)"
                Call EnumGroup(objMember, strOffset & "  ")
            Else
                if instr(strExceptions,lcase(objMember.sAMAccountName) & ",") <1 then 
					'wscript.echo "instr(strExceptions," & lcase(objMember.sAMAccountName) & "), = '" & instr(strExceptions,lcase(objMember.sAMAccountName) & ",") & "'"
					Wscript.Echo strOffset & objMember.sAMAccountName
					strUserDisplayName = ReturnDisplayName(objMember.sAMAccountName)
					Wscript.Echo strOffset & strOffset & strUserDisplayName
				end if
            End If
        Else
            Wscript.Echo strOffset & objMember.sAMAccountName & " (Duplicate)"
        End If
    Next
    Set objMember = Nothing
    Set adoRecordset = Nothing
End Sub

Function ReturnDisplayName(strLN) ' Credit to Markdmac ([URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1374874)[/URL]
    'Dim objConnection
	Dim objCommand
	Set objRootDSE = GetObject("LDAP://rootDSE")
    'Set objConnection = CreateObject("ADODB.Connection")
    adoConnection.Close
	adoConnection.Provider = "ADSDSOOBJECT"
    adoConnection.Open "ADS Provider"
    Set objCommand = CreateObject("ADODB.Command")
    'objCommand.ActiveConnection = objConnection
	wscript.echo "strDNSDomain ='" & strDNSDomain & "'"
    wscript.echo "strLN ='" & strLN & "'"
    adoConnection.CommandText = "<LDAP://" & strDNSDomain & _
        ">;(&(objectCategory=User)(samAccountName=" & strLN & "));displayName;subtree"
    'objConnection.CommandText = "<LDAP://" & objRootDSE.Get("DefaultNamingContext") & _
    '    ">;(&(objectCategory=User)(samAccountName=" & strLN & "));displayName;subtree"
    'objCommand.Properties("Page Size") = 99
    Dim objRecordSet : Set objRecordSet = adoCommand.Execute
    On Error Resume Next

    ReturnDisplayName = objRecordSet.Fields("displayName")

    On Error GoTo 0
    adoConnection.Close
End Function

So, my puzzle is, why is it failing there, when the code (appears to) work just fine in another script?

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
I think part of your problem is that you are mixing a lot of global defined variables/objects with those in the sub/functions.

Looking at your global variable and local...if you changed adoConnection in your sub to adoCommand it may work

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Belatedly (having just got back to work after getting hit in the eye by a baseball), sorted now, thank you.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top