Solved

Powershell AD Group Membership Query

Posted on 2014-02-26
2
398 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read value from xml file using vb.net 3 477
Python if statement 2 205
Technical requirements document 8 121
Outlook 2010  security hash generator - Unable to load hashctl.dll 12 372
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…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

776 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