I want to extract all the security groups and members of thoses group in AD

rated by 0 users
Not Answered This post has 0 verified answers | 5 Replies | 1 Follower

Not Ranked
4 Posts
dinesh_gurnaney posted on 02-12-2012 1:13 PM

 

I want to extract all the security groups and members of thoses group in AD  in one csv file
and want oouput in this  format

1)Group name SAM email address DN

members

2)Group name SAM email address DN

members

and so on

Any help will be Appreciated

All Replies

Top 25 Contributor
296 Posts
Microsoft MVP
Top Contributor

I presume that name, SAM, email-address and DN refer to the user

Do you want users and computers or just users.  What about nested groups?

Not Ranked
4 Posts

I want All Security groups and all the members

users,computers

Top 25 Contributor
296 Posts
Microsoft MVP
Top Contributor

You will have a slight problem because computers don't have email addreses.

Your script will also require multiple trips to the directory to look up information.

I'll assume that you don't want to deal with nested groups

Try this

function get-allgroupmembers {
Get-QADGroup | foreach {
$group = $_.Name
Get-QADGroupMember -Identity $($_.DN) |
foreach {
  $data = $null
  $dn = $_.DN
  switch ($($_.Type)){
    "user"{
        $user = Get-QADUser -Identity $dn
        $data = New-Object -TypeName PSObject -Property @{
         Group = $group
         Name = $($user.Name)
         SAM   = $($user.samaccountName)
         Email = $($user.Mail)
         DN = $($user.DN)
        }
    } 
   "computer" {
        $comp = Get-QADComputer -Identity $dn
        $data = New-Object -TypeName PSObject -Property @{
         Group = $group
         Name = $($comp.Name)
         SAM   = $($comp.samaccountName)
         Email = "None"
         DN = $($comp.DN)
         }
   }     
  }## end switch
 
  $data
} ## end inner foreach
} ## end outer foreach
}

use as

get-allgroupmembers | Export-Csv -Path allgroups.csv -NoTypeInformation

Not Ranked
4 Posts

Thanks for the help

It is showing me all the members and other information.but  i want  group name and than group members .It is not showing group name

Not Ranked
4 Posts

Thanks for the help I got it :)

Page 1 of 1 (6 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.