• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

Powershell AD Group Membership Query

I am looking to create a Powershell script that will export group name and user name then import this into a SQL table.  Need the export to be formatted with 2 columns GroupName and UserName.  Also need to be able to select multiple groups (as I don't want to export all the groups just 5 or so specific ones) I have found many export samples but none that will give me groupname and username side by side
1 Solution
Justin YeungSenior Systems EngineerCommented:
$OU = "Your AD OU"
$ExportPath = "Your Path"
$Groups = Get-Adgroup -Filter * -SearchBase $OU
foreach ($Group in $Groups)
$ADGroupMember = Get-ADGroupMember $Group.Name
if ($ADgroupmember.count -ne $null)
$EXport = $ADgroupMember | Select-Object Name,@{Name="GroupName"; Expression={$Group.Name}}}
$EXport  | Out-file $ExportPath -Append
geohixonAuthor Commented:
Great thank you for your quick response.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

Tackle projects and never again get stuck behind a technical roadblock.
Join Now