Solved

Powershell AD Group Membership Query

Posted on 2014-02-26
2
396 Views
Last Modified: 2014-02-27
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
0
Comment
Question by:geohixon
2 Comments
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 39890305
$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
}
0
 

Author Closing Comment

by:geohixon
ID: 39891749
Great thank you for your quick response.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I'd like to talk about something that is near and dear to my heart: build systems. Without them, building software is all about compiling locally, with software versions everywhere. It can be a mess. Today we are going to discuss building a small di…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now