Jump to content

Active Directory UDF - Help & Support (III)


water
 Share

Recommended Posts

To get a list of all properties for a user or computer etc. you could run the _AD_GetObjectProperties.au3 example script.

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

:)

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

Hey Water, Been awhile since I ran into a snag but I got another 1 for you that I am more than likely wrapping this all different directions.

The Goal: Query @username pull name out and add an identifier to the front of the name (variable used to create the new name im looking for) then use the new name to locate another ID. AKA Lastname, Firstname add 123 to be 123Lastname, Firstname then identify the Accountname with the 123Lastname, Firstname. I have had a few attempts and each time I get close I dont get it to where I want it.

This is what I have so far

Global $sFQDN0 = _AD_SamAccountNameToFQDN(@username)
Global $DisplayName0 = _AD_FQDNToDisplayname(@username)
Global $iPos = StringInStr($sFQDN0, ",")
Global $sOU = StringMid($sFQDN0, $iPos + 1)
Global $sGivenName = _AD_GetObjectAttribute(@UserName, "displayname")
$aObjects = _AD_GetObjectsInOU($sOU, "123" & $sGivenName, 2, "name")
MsgBox(0,"test",$aObjects)

I feel like I was on the right track but got off track and cant seem to line up the way I want. Right now I can validate 123Lastname, Firstname through its account as its valid and I have that in place I just want to be able to auto fill an input box by validating through AD the username is associated to a second ID which is the case for the ID I am testing. :) Hope i didnt get confusing and hoping I am a lot closer to on the right tracks. I used a Post you helped earlier with the example 3 on _AD_GetObjectsInOU.au3 to get to what I have. I can confirm the display is correct for $sGivenName but I cant get to acquiring the other attribute which I tried AD_GetObjectAttribute as well and still doesnt show the result I am looking for.

Thanks in advance. :)

Link to comment
Share on other sites

You need to add some kind of error checking to your script. Check for @error <> 0 after each call of an _AD_* function. I'm sure you'll get some errors returned.

What do you get when you run the following script (replace sensible data with wildcards)?

#include <ad.au3>
_AD_Open()

Global $sFQDN0 = _AD_SamAccountNameToFQDN(@username)
ConsoleWrite("FQDN: " & @error & " - " & $sFQDN0 & @CRLF)
Global $DisplayName0 = _AD_FQDNToDisplayname(@username)
ConsoleWrite("DisplayName: " & @error & " - " & $DisplayName0 & @CRLF)
Global $iPos = StringInStr($sFQDN0, ",")
#cs
Global $sOU = StringMid($sFQDN0, $iPos + 1)
Global $sGivenName = _AD_GetObjectAttribute(@UserName, "displayname")
$aObjects = _AD_GetObjectsInOU($sOU, "123" & $sGivenName, 2, "name")
MsgBox(0,"test",$aObjects)
#ce
_AD_Close()

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

@water no error is generated, The thing that I think isnt working for me is trying to find the display name from first username to locate the second username. I changed to messageboxes as sciTE-Lite(3.4.1) didnt want to write the data to the console. I am updating the version today, the standard install isnt blocked by our network but the update with the added tools is >.>.  The message box shows no error and the right data for the first part. the question I guess I am asking and trying to do is take the Display name add to it and search from the display name if that will work? Also will it be completely context driven to where I need to string match? If so I need to reduce out the last part of the displayname which I can do with string :)

Link to comment
Share on other sites

What I need to know: Is there a comma in the displayname?

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

How about this?

#include <ad.au3>
_AD_Open()

Global $aUser = _AD_GetObjectsInOU("", "(&(objectCategory=person)(objectClass=user)(samaccountname=" & @UserName & "))", 2, "ADsPath,Displayname,distinguishedName")
Global $sADsPath = $aUser[1][0] ; ADsPath
Global $sDisplayName0 = $aUser[1][1] ; Displayname
Global $sFQDN0 = $aUser[1][2] ; distinguishedName (FQDN)
Global $oUser = __AD_ObjGet($aUser[1][0]) ; Get user object
Global $oOU = __AD_ObjGet($oUser.Parent) ; Get parent of user object (= OU)
Global $sOUName = $oOU.Get("distinguishedName") ; Get distinguishedName (FQDN) for OU
MsgBox(0, "FQDN", $sFQDN0)
MsgBox(0, "Displayname", $sDisplayName0)
MsgBox(0, "OU", $sOUName)
$aUser123 = _AD_GetObjectsInOU($sOUName, '(&(objectCategory=person)(objectClass=user)(name=123'  & $sDisplayName0 & '*))', 2, "ADsPath,Displayname,distinguishedName")
MsgBox(0, "_AD_GetObjectsInOU", "@error: " & @error)
_ArrayDisplay($aUser123)

_AD_Close()

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

Error 3 means: No entries found.

The script I posted searches in the same OU where the first user (without 123) was found. Are there any additional spaces in the 123displayname?

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

No there is a value then a - before the last name. But i changed the 123 to that setup and it didnt locate it. I am double checking as I was reading what you posted I believe the separate IDs and do not belong in the same OU's. Basically 1 ID is a regular ID the other is an Admin ID. Both are tied to the same user which is the tricky part for me associating the looking it up.

Corrected spelling errors >.>

Edited by tweakster2010
Link to comment
Share on other sites

In your original post you were stripping the OU from the users FQDN and searching for the 2nd user in this OU.

To search the whole domain replace $sOUName with "" in the 2nd _AD_GetObjectsInOU.

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

Glad your problem could be solved!

I will take the code to retrieve the OU of an object and add it to the UDF as a new function.

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

This is all I kept to retrieve the data, now I just gotta have the Samaccount pulled from the other ID so I can write it into the input box from the array. I know its on the forums somewhere to writing from an array to a word doc/input box etc etc so I can get that last part done on my own im pretty sure.

But here is what I kept out of that for what I am doing.

#include <AD.au3>
_AD_Open()
Global $aUser = _AD_GetObjectsInOU("", "(&(objectCategory=person)(objectClass=user)(samaccountname=" & @UserName & "))", 2, "ADsPath,Displayname,distinguishedName")

Global $sDisplayName0 = $aUser[1][1] ; Displayname

$aUser123 = _AD_GetObjectsInOU("", '(&(objectCategory=person)(objectClass=user)(name=123'  & $sDisplayName0 & '*))', 2, "sAMAccountName,Displayname,distinguishedName")
_AD_Close()
Link to comment
Share on other sites

You can even make it a bit shorter:

#include <AD.au3>
_AD_Open()
Global $aUser = _AD_GetObjectsInOU("", "(&(objectCategory=person)(objectClass=user)(samaccountname=" & @UserName & "))", 2, "Displayname")
Global $aUser123 = _AD_GetObjectsInOU("", '(&(objectCategory=person)(objectClass=user)(name=123'  & $aUser[1] & '*))', 2, "sAMAccountName")
_AD_Close()

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

Nice Water i was working on the pulling the samaccount out for anyone who could use it the same way im posting what I did to snag it(I am new to arrays completely btw so i just used the helpfile to get what I have and it works) :)

#include <AD.au3>
_AD_Open()
Global $aUser = _AD_GetObjectsInOU("", "(&(objectCategory=person)(objectClass=user)(samaccountname=" & @UserName & "))", 2, "ADsPath,Displayname,distinguishedName")
Global $sDisplayName0 = $aUser[1][1] ; Displayname
$aUser123 = _AD_GetObjectsInOU("", '(&(objectCategory=person)(objectClass=user)(name=123'  & $sDisplayName0 & '*))', 2, "sAMAccountName,Displayname,distinguishedName")
$secondID =  _ArrayToString($aUser123,@TAB,1,1,@CRLF,0,0)
$SecondStringSplit = Stringleft($secondID,4)
_AD_Close()

Now I imagine the arraytostring part is overdone but that was using the one that lined up a lil better with how I was reading it :). But that allows me to auto fill the input with $secondID

I need lessons on spelling what, and, the. lol.

Edited by tweakster2010
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...