Jump to content

Active Directory UDF


water
 Share

Recommended Posts

Have never needed this information and can't test at the moment.

But you could run function _AD_GetObjectProperties agains a DNS server and then check the returned properties of any of them contains the needed information.

If you can find a script on the web (Visual Basic or similar) that returns the needed information it should be easy to translate it to AutoIt.

I searched but couldn't find anything.

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

No, not at the moment. You can only search for all queues or those queues on a specific spool server.

As the returned array contains the FQDN you could select those queues that match the desired OU.

If needed I could add a new parameter to the function to specify the starting OU and search depth.

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

Should be something like this (untested):

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_ListPrintQueues
; Description ...: Enumerates all PrintQueues in the AD tree,the specified spool server or OU.
; Syntax.........: _AD_ListPrintQueues([$sServername=*[, $sOU = ""[, $iSearchScope = 2]]])
; Parameters ....: $sServername  - Optional: Short name of the spool server to process
;                  $sOU          - Optional: The OU to retrieve from (FQDN) (default = "", equals "search the whole AD tree")
;                  $iSearchScope - Optional: 0 = base, 1 = one-level, 2 = sub-tree (default)
; Return values .: Success - One-based two dimensional array with the following information:
;                  |0 - PrinterName: Short name of the PrintQueue
;                  |1 - ServerName: SpoolServerName.Domain
;                  |2 - DistinguishedName: FQDN of the PrintQueue
;                  Failure - "", @error set
;                  |1 - There is no PrintQueue available. @extended is set to the error returned by LDAP
;                  |2 - Specified OU does not exist
; Author ........: water
; Modified.......:
; Remarks .......: To get more (including multi-valued) attributes of a printqueue use _AD_GetObjectProperties
; Related .......:
; Link ..........: http://msdn.microsoft.com/en-us/library/aa706091(VS.85).aspx, http://www.activxperts.com/activmonitor/windowsmanagement/scripts/printing/printerport/#LAPP.htm
; Example .......: Yes
; ===============================================================================================================================
Func _AD_ListPrintQueues($sServername = "*", $sOU = "", $iSearchScope = 2)

    If $sOU = "" Then
        $sOU = $sAD_DNSDomain
    Else
        If _AD_ObjectExists($sOU, "distinguishedName") = 0 Then Return SetError(2, 0, "")
    EndIf
    $__oAD_Command.Properties("Searchscope") = $iSearchScope
    $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sOU & ">;(&(objectclass=printQueue)(shortservername=" & $sServername & "));distinguishedName,PrinterName,ServerName"
    Local $oRecordSet = $__oAD_Command.Execute
    If @error Or Not IsObj($oRecordSet) Or $oRecordSet.RecordCount = 0 Then Return SetError(1, @error, "")
    Local $aPrinterList[$oRecordSet.RecordCount + 1][3] = [[0, 3]]
    $oRecordSet.MoveFirst
    Do
        $aPrinterList[0][0] += 1
        $aPrinterList[$aPrinterList[0][0]][0] = $oRecordSet.Fields("printerName").Value
        $aPrinterList[$aPrinterList[0][0]][1] = $oRecordSet.Fields("serverName").Value
        $aPrinterList[$aPrinterList[0][0]][2] = $oRecordSet.Fields("distinguishedName").Value
        $oRecordSet.MoveNext
    Until $oRecordSet.EOF
    $oRecordSet.Close
    Return $aPrinterList

EndFunc   ;==>_AD_ListPrintQueues

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

Great!

I will add this feature to the next version of the AD UDF!

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, im new here, 

im trying to   use your ADFunctions to made my life easy.  i usually needs  remove users from grups and and.. change, etc.

but to remove  the work is horrible. 

so.. i triying to  use your AD_RemoveUserFromGroup     script to   use a file ( with all the sammaccountnames to be removed ) and put the GROUP like its in your original script.

Any idea how can i do this?..

i read in some places   autoit can read excel files and colums...its possible adapt your AD_RemoveUserFromGroup script to use 1 colum for users and the other for the groups?

Best Regards and thanks in advance

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Sure this should be possible.

Simply combine the Excel UDF (comes with AutoIt) and my AD UDF.

_Excel_RangeRead retruns all cells in a worksheet into an array.

Then loop through this array and pass the group and user taken from each row to _AD_RemoveUserFromGroup.

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

#include <Excel.au3>
#include <AD.au3>

$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oExcel, "path to the Execel file to read")
$aTable = _Excel_RangeRead($oWorkbook)
_AD_Open()
For $i = 0 to UBound($aTable) - 1
    _AD_RemoveUserFromGroup($aTable[$i][0], $aTable[$i][1])
Next
_AD_Close()
_Excel_Close($oExcel)

Untested and without any error checking.

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

Try this. I added some error checking and display the data read from Excel.

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

$oExcel = _Excel_Open()
If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred at _Excel_Open")
$oWorkbook = _Excel_BookOpen($oExcel, "path to the Execel file to read")
If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred at _Excel_BookOpen")
$aTable = _Excel_RangeRead($oWorkbook)
If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred at _Excel_RangeRead")
_ArrayDisplay($aTable)
_AD_Open()
If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred at _AD_Open")
For $i = 0 to UBound($aTable) - 1
    _AD_RemoveUserFromGroup($aTable[$i][0], $aTable[$i][1])
    If @error Then Exit MsgBox(0, "Error", "Error " & @error & " occurred at _AD_RemoveUserFromGroup")
Next
_AD_Close()
_Excel_Close($oExcel)

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

mmm i read some about the Error 3 in the  RemoveUserFromGroup  manual page,

Then
    MsgBox(64, "Active Directory Functions - Example 1", "User '" & $sUser & "' is not a member of group '" & $sGroup & "'")

But the users gived in the Excel  Colum 1  exist in the Group ( is the samaccountname) and the Group too

any idea?

Link to comment
Share on other sites

My fault. Funktion _AD_RemoveUserFromGroup first requires the group, then the user. Should be:

_AD_RemoveUserFromGroup($aTable[$i][1], $aTable[$i][0])

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

its seems to work but .. i have a few questions

i have a domain admin in DOMAINX   .. the group is universal group of DOMAINX  but in the grup have users from the DOMAINY. 

when i use the script  to delete users from the group of the DOMAINX.. fails with error 2   ( users not exist ) 

 

the problem is the user when execute  the script? 

.... this script.. modify the user member of.. or  remove the object in the group?

 

Best Regards.

Link to comment
Share on other sites

Problem is that the UDF was only designed to work in a single domain.

The function checks user and group to be existant in the domain you have connected to when calling _AD_Open.

Then it retrieves the user and group object in the connected domain. As the user does not exist in the connected domain the function fails.

At the moment I do not have a solution for this problem.

If needed I will do some research and might provide a solution.

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...