-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGet-NestedGroups.ps1
More file actions
38 lines (33 loc) · 1.04 KB
/
Get-NestedGroups.ps1
File metadata and controls
38 lines (33 loc) · 1.04 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
function Get-ADNestedGroups($DN) {
$groups = [System.Collections.Generic.Dictionary[string, [System.Collections.Generic.List[int]]]]::new()
$parents = [System.Collections.Generic.Stack[string]]::new()
function Start-EnumWorker($parent) {
$group = Get-ADObject -Properties memberOf -Identity $parent
if (-not $groups.ContainsKey($parent)) {
$parents.Push($parent)
$groups.Add($parent, @(0, ($parents.Count)))
$group.MemberOf | ForEach-Object {
Add-GroupCount
Start-EnumWorker $_
}
$_ = $parents.Pop()
}
}
function Get-Spaces($count) {
for ($i = 1; $i -lt $count; $i++) {
" "
}
}
function Add-GroupCount() {
$parents | ForEach-Object {
$groups[$_][0] += 1
}
}
Start-EnumWorker $DN
$groups.Keys | ForEach-Object {
[pscustomobject]@{
DN = "$(Get-Spaces $groups[$_][1])$_"
SubGroups = $groups[$_][0]
}
}
}