Jump to content

Active Directory - Get username using Email address


TheOne23
 Share

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. :)

Link to comment
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
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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()

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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