Jump to content

Active Directory Scripts


Johny Clelland
 Share

Recommended Posts

Hi arcker,

thanks for your fast answer!

I searched the web and found a site (http://www.tools4net.de/doc/ad.htm - unfortunately in german) where all the AD attributes are listed. Description is one of these that can have multiple values.

Even when there is only one value for this attribute _ADGetObjectsInOU doesn't return it.

Therefore I'll have to use _ADGetObjectAttribute(<samaccountname>,"description")

Thanks for your help

Thomas

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

  • 3 weeks later...

I have been trying to use the _ADCreateUser() part of ADFunctions.au3, version 3.1.6 ...

Where did you find version 3.1.6? At the download area there seems to be version 3.1.3

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 a tremendous utility!! I've been looking for something like this for a long time!!

I'd really appreciate it if someone would show me how to generate a report (using this utility, of course) that could show: All Computers in AD, All Active User Accounts in AD, All disabled computer accounts, All disabled user accounts, etc.)

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

Hello,

When I'm running my script I use _ADObjectExists.

I have the following error:

1. If I'm using this function more than ~3900 times, then I get an error (com error 0x000000a9).

2. If' I'm running the function for 3000 times, than close the program and running it again then it's OK.

3. If' I'm running the function for 3000 times, and then running it again without closing the program, then it fails again with the same error.

* This error occurs in several AD environments (Some AD environment are OK)

Please Help

Link to comment
Share on other sites

I'd really appreciate it if someone would show me how to generate a report (using this utility, of course) that could show: All Computers in AD, All Active User Accounts in AD, All disabled computer accounts, All disabled user accounts, etc.)

First you'll have to create the LDAP queries, then use _ADGetObjectsInOU (Returns a filtered list of objects and attributes in a given OU)
_ADGetObjectsInOU($asUser, $sOU, "(&(objectCategory=user)(!department=*))", 2, "department,cn,distinguishedName,sAMAccountName")
This selects all users in $sOU where the field "department" is set. Every line in array $asUser will consist of 4 columns.

For some LDAP examples please see post. A very valuable tool to explore your AD is ADExplorer from Sysinternals (now M$).

Before calling a function from adfunctions.au3 please please have a look at the code because some functions need a sAMAccountName, others need a FQDN - so you might have to translate using _ADDNToSamAccountName or _ADSamAccountNameToFQDN.

If you have further questions, just drop me a note.

Edited by water

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

Hi robilev,

I noticed the same problem. I had to put a Sleep(100) after each call to AD then the problem went away.

HTH

Thomas

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

If anyone has any suggestions of other AD Functions they would like to see, or that they would like to share, then let me know.

I am always having to create scripts to search through AD for all the computers on the domain and then do something with them - usually pull some random information the bosses think is vitally important to know asap.

I mostly do this with VBScript, but I am liking AutoIT a whole lot more. About to begin trying to do it a bit easier in AutoIT, cause my VBScript uses manually input OUs to search through....

Link to comment
Share on other sites

Here's what I would like to do (using these functions), but I'm clueless at how to make it happen :)

- Get a list of all disabled user accounts in AD

- Take that list and check to see if the user is in any security or distribution groups

- If so, remove them from all those groups

Anyone have something like that they would care to share????? :)

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

To get information out of the AD you have to create a LDAP query. When you feed this query to _ADGetObjectsInOU you get an array of all objects.

To get all disabled users I have found the following LDAP query to work.

(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))
See this link for further information. This link lists the useraccount enumeration.

So the adfunctions call would look like:

_ADGetObjectsInOU($asUser, $sOU, "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))", 2, "department,cn,distinguishedName,sAMAccountName")oÝ÷ Ù8^jºÚËMújÅ,"W(Ȭ¶íç(駱שj»fz{ج¶)àº+!yÓZæ§vÀÇ(º{Mjg¨}ëÞ¯'b±¦åyÖr§·Mú¢èZ²Úyø¥çpØmë-j»bz
7ê

Please have a look at every function in adfunctions.au3 because there you see the format of the parameters the function requires (sAMAccountname or FQDN)

I always recommend ADExplorer from www.sysinternals.com (now M$). For further sources please search the forum for my older postings (LDAP queries etc.)

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

Thank you very much, Water. I will go through this information and see if I can make it work to meet my needs.

To get information out of the AD you have to create a LDAP query. When you feed this query to _ADGetObjectsInOU you get an array of all objects.

To get all disabled users I have found the following LDAP query to work.

(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))
See this link for further information. This link lists the useraccount enumeration.

So the adfunctions call would look like:

_ADGetObjectsInOU($asUser, $sOU, "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))", 2, "department,cn,distinguishedName,sAMAccountName")oÝ÷ Ù8^jºÚËMújÅ,"W(Ȭ¶íç(駱שj»fz{ج¶)àº+!yÓZæ§vÀÇ(º{Mjg¨}ëÞ¯'b±¦åyÖr§·Mú¢èZ²Úyø¥çpØmë-j»bz
7ê

Please have a look at every function in adfunctions.au3 because there you see the format of the parameters the function requires (sAMAccountname or FQDN)

I always recommend ADExplorer from www.sysinternals.com (now M$). For further sources please search the forum for my older postings (LDAP queries etc.)

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

WISH LIST FOR ADFUNCTIONS:

1.) I would like to see a function that will force a password change for a specified user -- sets the "User must change password at next login" checkbox.

2.) I would like to see a function that will check if the account is locked out.

3.) I would like to see a function that will allow you to unlock a user account.

:o

Anyone already have these functions and wish to share?!? :)

Edited by rogerd2u

Roger O."When people show you who they are, believe them.” --Mark Twain

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

hi..

I am all new to autoit and is trying to use the adfunctions.au3 and my problem is properly very basic.

When is try to get all user in a group i get an error in line 418 - Error Object referenced outside a "with" statement.

$membersadd = $objrecordset.fields(0).Value

$membersadd = $objrecordset.fields(0)^Error.

I have declared

dim $test[1500]

and is calling _adgetgroupMembers like this and ad_dlh is a group with in our ad (univeral, security)

$group = "ad_dlh"

_ADGetGroupMembers ($test, $group)

Link to comment
Share on other sites

For _ADGetGroupMembers you'll need the Full Qualified Domain Name (FQDN). You provide the sAMAccountName. Use _ADSamAccountNameToFQDN to convert a sAMAccountName to a FQDN. So your call would look like:

_ADGetGroupMembers($test,_ADSamAccountNameToFQDN($group))

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

For _ADGetGroupMembers you'll need the Full Qualified Domain Name (FQDN). You provide the sAMAccountName. Use _ADSamAccountNameToFQDN to convert a sAMAccountName to a FQDN. So your call would look like:

_ADGetGroupMembers($test,_ADSamAccountNameToFQDN($group))

Thx - it works :-)

Link to comment
Share on other sites

I haven't done it myself but you use try _ADGetGroupMemberOf

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...