Sign in to follow this  
Followers 0
Vaeb

Read an Active Directory Attribute

5 posts in this topic

Hi guys!

I would like to read the Attribute "Location" of a printer.

This is how my script looks:

; _ADGetObjectAttribute
    ; Retrieves the specified (single-value) attribute for the given SamAccountName
    ; Returns 0 if the object does not exist, the attribute does not exist for that
    ; object or if the value is multi-string.
    ; Otherwise returns the result


    Dim $objConnection
    Dim $strHostServer
    Dim $strDNSDomain
    $object = "PNMarketingC22PCL"
    $attribute = "Location"

    MsgBox(0,"klsda","Result: " & _ADGetObjectAttribute($object,$attribute))

    Func _ADGetObjectAttribute($object, $attribute)
        If _ADObjectExists($object) = 0 Then Return 0

        $strHostServer = "server27"
        $strDNSDomain = "CN=PVSVPS001"
        
        $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
        $objRecordSet = $objConnection.Execute ($strQuery)  ; Retrieve the FQDN for the object
        $ldap_entry = $objRecordSet.fields (0).value
        $oObject = ObjGet($ldap_entry)  ; Retrieve the COM Object for the object
        $result = $oObject.Get ($attribute)
        $oObject.PurgePropertyList
        $oObject = 0
        If $result = "" Then
            Return ""
        Else
            Return $result
        EndIf
        
    EndFunc   ;==>_ADGetObjectAttribute

    Func _ADObjectExists($object)
        $strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(sAMAccountName=" & $object & ");ADsPath;subtree"
        $objRecordSet = $ObjConnection.Execute ($strQuery)  ; Retrieve the FQDN for the group, if it exists
        
        If $objRecordSet.RecordCount = 1 Then
            $objRecordSet = 0
            Return 1
        Else
            $objRecordSet = 0
            Return 0
        EndIf
    EndFunc   ;==>_ADObjectExists

When I start, I get this error:

H:\AutoIt\Printer\AD_read_prop.au3 (39) : ==> Variable must be of type "Object".: 
$objRecordSet = $ObjConnection.Execute ($strQuery) 
$objRecordSet = $ObjConnection^ ERROR

Greets

Vaeb

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Have you tried using ObjCreate instead of ObjGet?

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0