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.GroupSc ope}},
@{Name='MemberName'; Expression={$_.Name}},
@{Name='MemberSamAccountNa me'; Expression={$_.SamAccountN ame}} |
Export-Csv -NoTypeInformation -Path 'C:\Group Listing.csv'
Thanks.
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.GroupSc
@{Name='MemberName'; Expression={$_.Name}},
@{Name='MemberSamAccountNa
Export-Csv -NoTypeInformation -Path 'C:\Group Listing.csv'
Thanks.
Are you getting the "invalid enumeration context" error?
ASKER
I am not getting any errors. I just need the output file to show the following attributes:
Group
GroupType
GroupMember
Group
GroupType
GroupMember
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great. It's what I needed. Thanks.
You're welcome. Thanks for the grade. Good luck!