Jump to content

Read an Active Directory Attribute


Recommended Posts

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

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...