Jump to content
Sign in to follow this  
SlowCoder74

Getting filtered computer names from Active Directory

Recommended Posts

SlowCoder74

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
SlowCoder74

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

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  

×