Sign in to follow this  
Followers 0
noob62

Looking up a specific user in Active Directory

6 posts in this topic

I'm trying to look up the OU a user resides in based on the username that is in the array. I'm using the AD.au3 udf for the lookup in AD, I may be doing something wrong with the assignment of the user name. When I run the script I get the following error:========================================================

COM Error Encountered in testcsv2.0.au3

AD UDF version = 1.3.0

@AutoItVersion = 3.3.8.1

@AutoItX64 = 0

@Compiled = 0

@OSArch = X64

@OSVersion = WIN_7

Scriptline = 540

NumberHex = 000000A9

Number = 169

WinDescription = Variable must be of type 'Object'.

Description =

Source =

HelpFile =

HelpContext = 544040308

LastDllError = 0

========================================================

Looking for some guidance.

#include <array.au3>
#include <AD.au3>

Opt("MustDeclareVars", 1)

Dim $sCSV = FileRead("C:\test.csv")

Local $arr = _CsvToArray2D($sCSV)
Local $n
Local $row = UBound($arr)

;Converts CSV to a 2D array.
Func _CsvToArray2D($sCSV)
Local $aTmp = StringRegExp($sCSV & @CR, '(\V*)\v{1,2}', 3)
Local $NumCols[UBound($aTmp)]
For $x = 0 To UBound($aTmp) - 1
StringReplace($aTmp[$x], ",", ",")
$NumCols[$x] = @extended + 1
Next
Local $Max = _ArrayMax($NumCols, 1)

Dim $aArr[UBound($aTmp)][$Max]

For $i = 0 To UBound($aArr, 1) - 1
Local $aTemp = StringSplit($aTmp[$i], ",")
For $j = 0 To $aTemp[0] - 1
$aArr[$i][$j] = $aTemp[$j + 1]
Next
Next
Return $aArr
EndFunc

;Search AD for the user OU
While $n < $row
Local $Group, $iAD_Security, $sAD_UserIdParam, $sAD_PasswordParam, $sAD_User, $device

$device = $arr[$n][0]
$sAD_User = $arr [$n][1]

_AD_Open($sAD_UserIdParam = "", $sAD_PasswordParam = "", $iAD_Security = 1)
$Group = _AD_GetUserPrimaryGroup($sAD_User)
_AD_Close()
$n = $n + 1
WEnd

Share this post


Link to post
Share on other sites



Your _AD_Open statement is wrong. If you need a secure connection use

_AD_Open("", "", "", "", "", 1)

BTW: Don't do _AD_Open/_AD_Close in the While loop. Open the connection to AD, loop through your data and then close the connection.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the help!

Just two other questions

Is this the correct way to pass a user name to look up their OU in AD. For instance if $sAD_User gets set to jdoe will it pull back widget factory for the OU when it looks up jdoe in AD?

$sAD_User = $arr [$n][1]
$Group = _AD_GetUserPrimaryGroup($sAD_User)

The second part to the last while statement will have the script write the OU to the device name via API of another product the only thing is when you access the API it prompts a windows security login for the user which is fine unless the script is looking up 50+ devices. Will the HTTP UDF allow the user to enter their credentials once so they wont have to keep inputting that information when the script is running? I know the forum rules about password stuff, I'm not trying to bypass security settings with this script

Edited by noob62

Share this post


Link to post
Share on other sites

1) If you query user jdoe by using _AD_GetUserPrimarygroup you will get a Fully Qualified Domain Name (FQDN). If you need further properties of the user you should call _AD_GetObjectProperties and pass this FQDN. You get all or selected properties in an array.

2) Don't know. We would need more information about that.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

For instance I want the script to do the following after it gets the user OU

ShellExecute("https://localhost:8081/remote/system.applyTag?names=" & $device & "&tagName=" & $Group)

But when accessing the API it requires a windows security login before it will apply the tag to a device. I'm looking for a way that the user can enter their info once instead of each time the script tries to access the API.

Share this post


Link to post
Share on other sites

It depends on the application. Either it provides a way to login, do all the needed processing and then log out. Or you need to use the IE UDF to provide the needed credentials.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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  
Followers 0