Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell AD Group Membership Query

Posted on 2014-02-26
2
Medium Priority
?
422 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
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.

927 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