Skip to content

Instantly share code, notes, and snippets.

@irwins
Last active January 27, 2016 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irwins/6314f11bcd84cb78c21e to your computer and use it in GitHub Desktop.
Save irwins/6314f11bcd84cb78c21e to your computer and use it in GitHub Desktop.
<#
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