-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathADGroupMemberList.ps1
More file actions
55 lines (46 loc) · 1.4 KB
/
Copy pathADGroupMemberList.ps1
File metadata and controls
55 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
# Created By: Tyler.Filkins
# Created Date: 2016-10-21
#
# Description: This script performs recursive queries for the members of Active Directory groups.
# If any group members are themselves a group, then the script will also query for
# that groups members, and so on..
#
#
# *** BEFORE YOU USE THIS SCRIPT! ***
# Make sure you've installed the Active Directory PowerShell Module or else the cmdlet Get-ADGroup will not work.
#
#>
function getGroupMembers($group)
{
$names_list = @()
foreach($name in $group.Members)
{
if($name -like "*Groups*")
{
$grp = Get-ADGroup $name -Properties Members
$names_list += getGroupMembers($grp)
}
else
{
$obj = [pscustomobject] @{
name = ($name.Split('=')[1]).Split(',')[0]
group = $group.name }
$names_list += $obj
}
}
return $names_list
}
#-------------------------#
# EXECUTION STARTS HERE #
#-------------------------#
$date = (Get-Date).GetDateTimeFormats()[5]
$group_members_list = @()
$export_filepath = "C:\temp\$date.csv"
$searchbase = "<AD_search_base>"
$groups = Get-ADGroup -Filter * -Properties * -SearchBase $searchbase
foreach($group in $groups)
{
$group_members_list += getGroupMembers($group)
}
$group_members_list | Export-Csv $export_filepath -NoTypeInformation