Jump to content
Sign in to follow this  
CassidyHunt

Active Directory OU Query Help

Recommended Posts

CassidyHunt

I have a OU structure that looks like this:

company->location->department->user

Based on those three tiers I want to map particular drives. I downloaded the adfunctions.au3 script and can get the entire tree view. I am having an issue figuring out how to build a function that accepts the user name and spits out an array that tells me these levels.

Any help is greatly appreciated.

Thanks

Cassidy

Share this post


Link to post
Share on other sites
water

I have a OU structure that looks like this:

company->location->department->user

Based on those three tiers I want to map particular drives. I downloaded the adfunctions.au3 script and can get the entire tree view. I am having an issue figuring out how to build a function that accepts the user name and spits out an array that tells me these levels.

Any help is greatly appreciated.

Thanks

Cassidy

The successor of adfunctions.au3 is AD.au3 (for download please see my signature). It has more functions, example scripts and a help file.

To get the OU you could translate the username to a Fully qualified domain name (FQDN or distinguished name) and then split it into pieces using stringsplit.

#include <AD.au3>
_AD_Open()
$sFQDN = _AD_SamAccountNameToFQDN(@UserName)
$aOU = Stringsplit($sFQDN,",")
For $iIndex = 1 to $aOU[0]
    If StringLeft($aOU[$iIndex],3) = "OU=" Then ConsoleWrite(StringMid($aOU[$iIndex],4) & @CRLF)
Next
_AD_Close()
Exit

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - 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
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
CassidyHunt

The successor of adfunctions.au3 is AD.au3 (for download please see my signature). It has more functions, example scripts and a help file.

To get the OU you could translate the username to a Fully qualified domain name (FQDN or distinguished name) and then split it into pieces using stringsplit.

#include <AD.au3>
_AD_Open()
$sFQDN = _AD_SamAccountNameToFQDN(@UserName)
$aOU = Stringsplit($sFQDN,",")
For $iIndex = 1 to $aOU[0]
    If StringLeft($aOU[$iIndex],3) = "OU=" Then ConsoleWrite(StringMid($aOU[$iIndex],4) & @CRLF)
Next
_AD_Close()
Exit

That is exactly what I needed. Thanks. I didn't see your signature but I will search the web for the link.

Thanks again.

Cassidy

Share this post


Link to post
Share on other sites
water

My signature is the text below.

Just click on "Download page"

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - 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
 
Tutorials:

ADO - 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  

×