Jump to content

How to sort AD metadata.


Recommended Posts

Hello.

The below code creates a file with all groups an employee is member of as first requested on each line. Not sorted.

So the file contains this:

DSTSN,Share,Allround,Workday,Festi

DSKVK,Allround,Festi

How can I sort the same metadata so it looks like this:

DSTSN,Share ,Allround   ,Workday    ,Festi
DSKVK,      ,Allround   ,           ,Festi

 

#include <AD.au3>

Const $sFilePath = StringReplace(@ScriptFullPath,"au3","txt")
Global $aGroups, $aUsers, $sOU = "", $sGroups, $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
; Open the file for writing (append to the end of a file) and store the handle to a variable.
If $hFileOpen = -1 Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
EndIf

; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

$sOU = InputBox('Get members from groups', 'Please enter OU as Fully Qualified Domain Name (FQDN)', "OU=Users,OU=so,OU=dk,OU=company,DC=ad,DC=company,DC=org")
If _AD_ObjectExists($sOU) Then
    $aUsers = _AD_GetObjectsInOU($sOU)
    _ArrayDelete($aUsers, 0)
    For $c = 0 To 10 ;UBound($aUsers)-1
        If _AD_ObjectExists($aUsers[$c]) Then
            $aGroups = _AD_GetUserGroups($aUsers[$c])
            _ArrayDelete($aGroups, 0)
            For $i = 0 to UBound($aGroups)-1
                $sGroups &= StringMid($aGroups[$i],4,StringInStr($aGroups[$i],",")-4) & ";"
            next
            $sGroups = StringTrimRight($sGroups, 1)
            FileWrite($hFileOpen, $ausers[$c] & ";" & $sGroups & @CRLF)
        EndIf
        $sGroups = ""
    Next
EndIf
FileClose($hFileOpen)

; Close Connection to the Active Directory
_AD_Close()

 

 

 

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

Why do you need to sort the groups this way?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 want to compare membership in AD groups (=permissions) for multiple persons, departments etc. you could have a look at my ADAudit tool:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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...