-
-
Save irwins/6314f11bcd84cb78c21e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Author: I.C.A. Strachan | |
Version: | |
Version History: | |
Purpose: Get User nested group membership report | |
#> | |
[CmdletBinding()] | |
param( | |
[string] | |
$Identity | |
) | |
function Get-ADUserGroups { | |
param ($Group,$indent,$Parent) | |
Get-ADGroup –Identity $Group –Properties MemberOf | | |
Select-Object -ExpandProperty MemberOf | | |
ForEach-Object { | |
$GroupName = ($_).Split(',')[0].Split('=')[1] | |
if(!(($Parent).Contains($GroupName))){ | |
$Newparent = "$Parent/$GroupName" | |
[PSCustomObject]@{ | |
Group = $GroupName.PadLeft($GroupName.Length + ($indent*5),'_') | |
Name = $GroupName | |
NestedLevel = $indent | |
InheritedFrom = $Parent | |
} | |
Get-ADUserGroups -Group $_ -indent ($indent+1) -Parent $Newparent | |
} | |
else{ | |
[PSCustomObject]@{ | |
Group = $GroupName.PadLeft($GroupName.Length + ($indent*5),'_') | |
Name = $GroupName | |
NestedLevel = $indent | |
InheritedFrom = "$GroupName/Circulair. Please review" | |
} | |
} | |
} | |
} | |
#region Main | |
Get-ADUser -identity $Identity -Properties MemberOf | | |
Select-Object -ExpandProperty MemberOf | | |
ForEach-Object { | |
$GroupName = ($_).Split(',')[0].Split('=')[1] | |
[PSCustomObject]@{ | |
Group = $GroupName | |
Name = $GroupName | |
NestedLevel = 0 | |
InheritedFrom = $null | |
} | |
Get-ADUserGroups -Group $_ -indent 1 -Parent $GroupName | |
} | | |
Out-GridView | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment