I want to extract all the security groups and members of thoses group in AD in one csv fileand want oouput in this format
1)Group name SAM email address DN
members
2)Group name SAM email address DN
and so on
Any help will be Appreciated
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?
I want All Security groups and all the members
users,computers
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 = $_.NameGet-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
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
Thanks for the help I got it :)