Jump to content

Recommended Posts

Posted (edited)

I need to run a presumably simple search for computers in AD.

From a search, I found this thread:

and downloaded adfunctions.au3.

Here is my code:

#include "H:AutoIT Projects_Routinesadfunctions.au3"
Global $aComputers
$sOU = $strDNSDomain
$retVal = _ADGetObjectsInOU($aComputers,$sOU,"(objectclass=computer,name=nfdv*)",2,"name")
msgbox(0,"",$retVal)
_ArrayDisplay($aComputers)

Based on notes in the adfunctions routine, I added "name=nfdv*" to retrieve all PCs starting with "nfdv", which should yield about 50. It took just a few seconds, but the $retVal = 0, which is (from what I can tell) the return code for no objects found.

I don't know if it helps at all, but the computernames I need are nested 2 layers deep from the top domain.  In other words:
MyDomain top
  > OU 1
    > OU 2
      computername1
      computername2
      ... etc. ...

Also, if I need to get the object description, is the proper fieldname to add to $datatoretrieve called "description"?

Edited by SlowCoder74
Posted

Download my AD UDF (it's the successor of the adfunctions UDF). Then your script should look like this:

#include "H:\AutoIT Projects\_Routines\AD.au3"
_AD_Open()
Global $aComputers = _ADGetObjectsInOU("","(&(objectclass=computer)(name=nfdv*))",2,"name")
If @error then MsgBox(16, "Error", "Error returned by _AD_GetObjectsInOU. @error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aComputers)
_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

 

Posted (edited)

Excellent! That works.

Now, I'm trying to obtain the descriptions of the computers. I change the field list to "name,description", The output adds another field, but the 2nd field is blank. When I look in AD, the descriptions are full of data. Am I missing something?

Even when I just put in "description", the data is blank.

Scratch that. I played with the code a bit more, and it's working now. Thank you!

Edited by SlowCoder74

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
×
×
  • Create New...