Jump to content

[RESOLVED]Can Autoit filter like Powershell?


Recommended Posts

Is there a way to be able to filter like power can filter?

Like the way this powershell script filters for instance:

Import-Module ActiveDirectory
Get-ADUser -Filter {EmailAddress -eq "$Usersemailaddress"}| Select-Object -ExpandProperty SamAccountName | Out-File C:\Users\"$env:username"\Desktop\email2samconversion.txt
 

Goal is trying to get the SamAccountName by filtering with the email address of a user in AD.

I have the AD.UDF but it only works with the Sam and the FQDN. i've tried running powershell in Autoit, but it takes at least 7 seconds to start Powershell>import the module>create the text file>read the text file>Delete the textfile from desktop>Display in Edit box in GUI. I'm wondering if there is a way to filter the search function of AD through autoit kind of like how Powershell does.

i've not yet been able to powershell to run properly in Autoit either:

I tried:

Run(powershell -Command Import-Module ActiveDirectory | Get-ADUser -Filter {mail -eq "$UserEmail"} | Select-Object -ExpandProperty SamAccountName | Out-File C:\users\$env:username\desktop\SamaccountNametextfile.txt")

But it keeps failing. I tried using ShellExecute as well and neither of them worked.

Edited by Quantumation
Figured it out, thanks to water
Link to comment
Share on other sites

So you want to retrieve users based on their emailaddress?
This should be possible with _AD_GetObjectsInOU.
Can't test at the moment but if you like I can provide an example.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

#include <AD.au3

Func EmailConvertSam()
    _AD_Open()
    If @error Then Exit MsgBox(16, "Active Directory", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)
    Local $Email = GUICtrlRead($emailaddress)
    $aObjects = _AD_GetObjectsInOU("", "(mail=" & $Email & ")", 2, "sAMAccountName", "sAMAccountName")
    _ArrayDisplay($aObjects)
    _AD_Close()
EndFunc   ;==>EmailConvertSam

@water I figured it out, no need for an example. I'll mark this topic as resolved.

Thank you for the accurate direction, very appreciated.

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

×
×
  • Create New...