Link to home
Start Free TrialLog in
Avatar of Kenneth Cameron
Kenneth Cameron

asked on

Pull groups from Active Directory

Hi,

I am trying to finish up a PowerShell script to where I am pulling a listing of groups from Active Directory and export them to a .csv file.  I need the script to also output the group-type (security, distribution).  Here is what I have so far:

Get-ADGroup -Filter {GroupCategory -eq "Security"} | ForEach-Object {
      $Group = $_
      Get-ADGroupMember -Recursive -Identity $_.DistinguishedName
} | Select-Object -Property `
            @{Name='GroupName'; Expression={$Group.Name}},
            @{Name='GroupType'; Expression={$Group.GroupScope}},
            @{Name='MemberName'; Expression={$_.Name}},
            @{Name='MemberSamAccountName'; Expression={$_.SamAccountName}} |
      Export-Csv -NoTypeInformation -Path 'C:\Group Listing.csv'

Thanks.
Avatar of netcmh
netcmh
Flag of United States of America image

Are you getting the "invalid enumeration context" error?
Avatar of Kenneth Cameron
Kenneth Cameron

ASKER

I am not getting any errors. I just need the output file to show the following attributes:

Group
GroupType
GroupMember
ASKER CERTIFIED SOLUTION
Avatar of netcmh
netcmh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great.  It's what I needed.  Thanks.
You're welcome. Thanks for the grade. Good luck!