إضغط لتفاصيل الإعلانات



Results 1 to 1 of 1
Share
  1. #1
    Join Date
    Nov 2007
    Location
    Arab world!
    Posts
    6,169
    Blog Entries
    4
    Rep Power
    10

    Thumbs up Export all group members of one or more particular groups in Active Directory Domain

    Export all group members of one or more particular groups in Active Directory Domain

    You can Use this for Group Audit

    Dear All,
    I'll give you two different ways to export Domain Group members.

    1. Simple way
    Code:
    csvde -f c:\Groups.csv -r "(sAMAccountName=CSRM-Web)" -l member

    2. With powershell script,batch file
    script will have three files groupaudit.bat ,groupaudit.ini and groupaudit.ps1 and all are on the same folder.



    groupaudit.bat
    Code:
    @echo off
    powershell .\groupaudit.ps1

    groupaudit.ini
    Code:
    CN=GROUPNAME,OU=Groups,OU=Corp,DC=ChildDomainName,DC=EgyEng,DC=com
    You list the groups you want to export their members each in one line with syntax above.

    groupaudit.ps1
    Code:
    function Get-Members
        {
            param ($groupDN)
            
            $nested = @()
            $nesting = "false"
            $nl = [Environment]::NewLine
            $group = [ADSI] "LDAP://$groupDN"
            
            $retval = "Members of group: " + $group.cn + " (" + $group.distinguishedName + ")"
            
            foreach ($member in $group.member)
                {
                    $user = new-object directoryservices.directoryentry("LDAP://$member")
                    if ($user.objectclass -contains "group")
                        {
                            $retval = $retval + $nl + "+" + $user.cn
                            $nesting = "true"
                            $nested += $user.distinguishedname
                        }
                    else
                        {
                            $retval = $retval + $nl + $user.SAMAccountName
                        }
                }
            
            if ($nesting -contains "true")
                {
                    $retval = $retval + $nl + $nl + "Nested Group Members:"
                    foreach ($g in $nested)
                        {
                            $retval += $nl
                            $retval += Get-Members($g)
                            $retval += $nl
                        }
                }
            return $retval
        }
    
    foreach ($line in Get-Content ".\groupaudit.ini")
        {
            $output = ""
            $groupDN = $line
            $group = [ADSI] "LDAP://$groupDN"
            $groupName = $group.cn
            $runDate = Get-Date -format "yyyyMMdd-HHmmss"
            $outfile = ".\" + $groupName + "_" + $runDate + ".txt"
            
            Get-Members($groupDN) | Out-File -FilePath $outfile
        }
    You have the option to change the line of
    Code:
    $retval = $retval + $nl + $user.SAMAccountName
    instead of $user.SAMAccountName to $user.DisplayName to have a friendly name instead of login ID

    Also you can export a .csv file instead of .txt by change the line
    Code:
    $outfile = ".\" + $groupName + "_" + $runDate + ".txt"
    Change ".txt" to ".csv".

    i uploaded the full folder in the below link.
    http://www.4shared.com/rar/rOOQBZEd/groupaudit.html
    Last edited by Mohamed Fouad; 23-03-2013 at 02:04 AM.


  2. Facebook Comments - تعليقـك على الفيس بوك يسعدنا ويطور مجهوداتنـا


  3. Forum Ads:

  4. Forum Ads:

    اضفط هنا لمعرفة تفاصيل الإعلانات بالموقع


  5. Forum Ads:

    -->

Similar Threads

  1. Replies: 0
    Last Post: 26-12-2010, 06:31 PM
  2. Replies: 0
    Last Post: 05-08-2010, 08:38 PM
  3. Replies: 0
    Last Post: 27-05-2010, 01:27 PM
  4. some ways to Export Active Directory data
    By Mohamed Fouad in forum Microsoft
    Replies: 2
    Last Post: 05-05-2010, 04:36 PM
  5. Replies: 5
    Last Post: 30-01-2010, 03:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

أقسام المنتدى

الروابط النصية

تابع جروبنا على الفيس بوك

صفحة Egypt Engineers على الفيس بوك

تابعنا على linkedin

جروبنا على الياهو جروب