Get members of each groups
hi guys, i've got script need with. need put on txt or csv list of members each group discovered in particular ou tree i'm getting result lists if there 1 member of group.
$groups = get-adgroup -filter * -searchbase "ou"$result = @()
foreach ($group in $groups)
{
$members = get-adgroupmember -identity "$group"
$return = new-object psobject
$return | add-member noteproperty -name "groupname" -value $group.name
$return | add-member noteproperty -name "member" -value $members
$result += $return
}
$result | export-csv c:\test\securitygroups.csv -notypeinformation
any appreciated
thanks
the memers object in cases array or collection.
you need enumerate array , create array of psobjects each member.
like so:
$groups = get-adgroup -filter * -searchbase "ou" $result = @() foreach ($group in $groups){ $members = get-adgroupmember -identity "$group" foreach ($member in $members){ $psobject = new-object psobject $psobject | add-member noteproperty -name "groupname" -value $group.name $psobject | add-member noteproperty -name "member" -value $member $result += $psobject } } $result | export-csv c:\test\securitygroups.csv -notypeinformation
cheers
kriss milne | mcse | http://blog.krissmilne.tech | twitter | linkedin
note: posts provided “as is” without warranty of kind, either expressed or implied, including not limited implied warranties of merchantability and/or fitness particular purpose.
Windows Server > Windows PowerShell
Comments
Post a Comment