Jump to content

Active Directory UDF - Help & Support (III)


water
 Share

Recommended Posts

To work with computers you need to append a $ sign to the name.

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

Search the forum for 'how to post code'. I am not at a computer at the moment :(

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 so much for answering my previous questions. I am now trying to determine the number of computers that have logged in within the past $iDays days. Out of several hundred machines, the following code returns the exact same machines no matter what I change $iDays to.

#include <AD.au3>
#include <Date.au3>
#include <File.au3>

_AD_Open()

Global $aObjects, $sFilePath, $sAge, $iDays
Global $sOU = ""

$iDays = -30
$sFilePath = "Z:\Computer List\Active Computer List.txt"
$sAge = _DateAdd("D", $iDays, _NowCalcDate()) ; $sType, $iValToAdd, $sDate
$aObjects = _AD_GetObjectsInOU($sOU, "(&(objectClass=computer)(|(lastLogon=0)(lastLogon>=" & $sAge & ")))", 2, "Name")
$Result = MsgBox($MB_YESNOCANCEL, "Output", "Do you want to send output to Z:\Computer List\Computer List.txt." & Chr(13) & _
    "If you select No, the output will be displayed using ArrayDisplay")
If $Result = 6 then ; 2 = Cancel; 6 = Yes; 7 = No
    Output_To_File()
    Else
        Display_Array()
EndIf

_AD_Close()

Func Output_To_File()
    _FileWriteFromArray($sFilePath, $aObjects, 1)
    ShellExecute($sFilePath)
EndFunc ; Output_To_File

Func Display_Array()
    _ArrayDisplay($aObjects, "Computer Names")
EndFunc ; Display_Array()
Link to comment
Share on other sites

Can't test at the moment but I think the date formats don't match.

_DateAdd returns YYYY/MM/DD but the lastlogon date is stored as YYYYMMDD.

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

Drawing a blank! How do you query and get a 1 dimensional array of multiple attributes for a user object?

Similar to how you can return multiple attributes from _AD_GetObjectsInOU

(Even better if there is a way to do this with the _AD_RecursiveGetGroupMembers)

I need an array that contains the following

samaccountname,displayname,description,physicalDeliveryOfficeName

(recursively) for all members of a group.

Is this possible?

So far I'm doing something like this, but not having much luck.

#include <AD.au3>
#include <Array.au3>

_AD_Open()

Global $sGroup = "IS Department" ; group name

$aResult = _AD_RecursiveGetGroupMembers($sGroup, 10, True, False)

_ArrayDisplay($aResult)

For $i = 1 To UBound($aResult) - 1
    $aResult1 = _AD_GetObjectProperties($aResult[$i], "displayname,description,physicalDeliveryOfficeName")
    _ArrayDisplay($aResult1)
Next

_AD_Close()
Link to comment
Share on other sites

If you query multiple properties you get a 2D array.

You could loop through the 2D array returned by _AD_GetObjectProperties, concatenate the elements into a string and write this to the 1D array.

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 you query multiple properties you get a 2D array.

You could loop through the 2D array returned by _AD_GetObjectProperties, concatenate the elements into a string and write this to the 1D array.

Maybe a feature request then?

New function?

_AD_GetObjectAttributes

plural?!

ability to query for multiple attributes for a single object and return a 1-dimensional array.

Link to comment
Share on other sites

You are the first asking for this feature :)

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

:)

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

Issue with trying to query the 'lastlogon' attribute for computer objects.

#include <AD.au3>
#include <Array.au3>

_AD_Open()

Local $aResult = _AD_GetObjectsInOU("*", "(objectCategory=computer)", 2, "sAMAccountName, lastLogon")

_ArrayDisplay($aResult)

samaccountname populates correctly, but my second column is blank. The value is there as I can see it when I click on the attribute editor for a computer object in ADUC.

Link to comment
Share on other sites

The lastlogon attribute is a large integer data type. You need to use _AD_GetObjectsProperties or _AD_GetLastLoginDate to retrieve the decoded date.

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

  • Moderators

Define "computers list". Do you mean every computer that user has logged into, or the computer that user is logged into at the moment?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

As there is no link between user and computer you can't retrieve this information from AD (neither the logon history nor the currently logged on computer).

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

  • Moderators

You said username, the DisplayName is the name of the computer. Please clarify which you are after. What you're showing is the result of a GPO applied, as this is not normal behavior in my experience.

Edit: I realize that may be a little vague - In the example you post, the description is being filled out by either a GPO or script (or, god forbid, manually). If your configuration is like that, then yes you should be able to parse that data and get what you're after. If your domain does not have that GPO configured, you won't have that info in the Description field.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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

×
×
  • Create New...