Jump to content
Sign in to follow this  
TheOne23

Active Directory - Get username using Email address

Recommended Posts

Hi Experts / Water,

I've been doing some work with AD. I am able to return specific info given a username. However, I want the input to accept a format of "Email", search AD for a match and return the username. Is this possible?

I am using the AD.au3 but unable to see a function that works for this scenario.

Any help will be greatly appreciated. :)

Share this post


Link to post
Share on other sites

I think you meant 'Experts (especially water). You're excluding him from the experts there ;D


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites

Something like this?

#include <AD.au3>

; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

Global $aObjects = _AD_GetObjectsInOU("", "(ANR=john.Doe@company.com)", 2, "sAMAccountName,distinguishedName,displayname", "displayname")
If @error > 0 Then Exit MsgBox(64, "", "No records found")
_ArrayDisplay($aObjects)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
2 minutes ago, seadoggie01 said:

I think you meant 'Experts (especially water).

I understood it this way :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

As usual and expected, you made my day! 😎

It works like a charm! 

Thank you very much for your great and quick help on this.

below is how I used it:

_AD_Open()

Global $aOL_Item = _OL_ItemFind($oOutlook, "RonaldJayson_paggao@comcast.com\Inbox\BP_Automation", $olMail, "[UnRead]=True", "", "", "EntryID","",2)

    $oItem = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "body")
    $oItem1 = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "receivedtime")
    $oItem2 = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "subject")
    Global $oItem3 = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "senderemailaddress")

Global $oOL_Item = $oOutlook.Session.GetItemFromID($aOL_Item[1][0], Default)
    Global $oOL_Sender = $oOL_Item.Sender
   If $oOL_Sender.AddressEntryUserType = $olExchangeUserAddressEntry Or $oOL_Sender.AddressEntryUserType = $olExchangeRemoteUserAddressEntry Then
        Global $oExchangeUser = $oOL_Sender.GetExchangeUser
        ;MsgBox(0, "Mail", $oExchangeUser.PrimarySmtpAddress)
        $EmailAddress_Sender = $oExchangeUser.PrimarySmtpAddress
        ;MsgBox(0, "Mail", $EmailAddress_Sender)
   Else
        Global $EmailAddress_Sender1 = _ArrayToString($oItem3,"",1,1,"",1,1)
      $EmailAddress_Sender = StringStripWS($EmailAddress_Sender1,7)
   EndIf

If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

Global $aObjects = _AD_GetObjectsInOU("", "(ANR="& $EmailAddress_Sender &")", 2, "sAMAccountName,distinguishedName,displayname", "displayname")
If @error > 0 Then Exit MsgBox(64, "", "No records found")

_ArrayDisplay($aObjects)

$cn1 = _ArrayToString($aObjects,"",1,1,"",1,1)

Msgbox(64,"UserName: ",$cn1)

_AD_Close()

 

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...