Sign in to follow this  
Followers 0
Radsam

How do I search Active Directory for displayName

4 posts in this topic

I was unable to find anything in the forums regarding my issue.

I need to search AD to see if the "displayName" object exists. I already have the code to find if the "sAMAccountName" exists.

Ultimately, I need to have a script that allows me to search with EITHER "displayName" or "sAMAccountName" and display the object details.

Below is what I have for just the "sAMAccountName":

Local $sUserName = "Lastname, Firstname ABC:DE";our display names are formatted as shown.
Local $ADS_NAME_INITTYPE_GC = 3
Local $ADS_NAME_TYPE_NT4 = 3
Local $ADS_NAME_TYPE_1779 = 1
Local $sMemberOf = ""

Local $objRootDSE = ObjGet ("LDAP://RootDSE")
If @error Or $sUserName = "" Then
    MsgBox(0, 'Error', 'Username does not exist or not able to communicate with ' & @LogonDomain)
    Exit
Else
    $objTrans = ObjCreate ("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
;~      $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $sUserName)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet ("LDAP://" & $strUserDN)
    If @error Then
        MsgBox(0, 'Error', 'Username does not exist or not able to communicate with ' & @LogonDomain)
        Exit
    EndIf
EndIf


;Output object details...
ConsoleWrite($UserObj.displayName)
ConsoleWrite($UserObj.scriptPath)
ConsoleWrite($UserObj.HomeDirectory)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I was unable to find anything in the forums regarding my issue.

I need to search AD to see if the "displayName" object exists. I already have the code to find if the "sAMAccountName" exists.

Ultimately, I need to have a script that allows me to search with EITHER "displayName" or "sAMAccountName" and display the object details.

Below is what I have for just the "sAMAccountName":

Local $sUserName = "Lastname, Firstname ABC:DE";our display names are formatted as shown.
Local $ADS_NAME_INITTYPE_GC = 3
Local $ADS_NAME_TYPE_NT4 = 3
Local $ADS_NAME_TYPE_1779 = 1
Local $sMemberOf = ""

Local $objRootDSE = ObjGet ("LDAP://RootDSE")
If @error Or $sUserName = "" Then
    MsgBox(0, 'Error', 'Username does not exist or not able to communicate with ' & @LogonDomain)
    Exit
Else
    $objTrans = ObjCreate ("NameTranslate")
    $objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
;~      $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
    $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $sUserName)
    $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
    $UserObj = ObjGet ("LDAP://" & $strUserDN)
    If @error Then
        MsgBox(0, 'Error', 'Username does not exist or not able to communicate with ' & @LogonDomain)
        Exit
    EndIf
EndIf
;Output object details...
ConsoleWrite($UserObj.displayName)
ConsoleWrite($UserObj.scriptPath)
ConsoleWrite($UserObj.HomeDirectory)
Try using the _ADDNToDisplayName() for the display name in AD. If you don't have the adfunctions.au3 then you can get it here it has many AD functions you can use.

http://www.autoitscript.com/forum/index.ph...st&p=294788

Hope this helps.

Edit:

Or you can probably use _ADOUObjectNames()

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Can someone please provide example?

I need to be able to search AD with either a "displayName" or "sAMAccountName".

The idea is a user will type into an input field either of the above names and click a search button. The rest of my script finds either the "displayName" or "sAMAccountName" in AD and returns various attributes of the object.

I know how to search AD with the "sAMAccountName", but can someone give me an example of how to do so with the "displayName".

Share this post


Link to post
Share on other sites

bump

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