-
-
Save irwins/52c5fc7219e25f95e859cb235318b68c 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
$ADGroups = @{ | |
DomainLocal = @{} | |
Global = @{} | |
Universal = @{} | |
} | |
#region Get Members security Groups in AD | |
Get-ADGroup -Filter * | | |
ForEach-Object{ | |
$SamAccountName = $_.SamAccountName | |
switch ($_.GroupScope) { | |
'DomainLocal' { | |
$ADGroups.DomainLocal.$SamAccountName = Get-ADGroupMember -Identity $SamAccountName | Select-Object -ExpandProperty SamAccountName | |
} | |
'Global'{ | |
$ADGroups.Global.$SamAccountName = Get-ADGroupMember -Identity $SamAccountName | Select-Object -ExpandProperty SamAccountName | |
} | |
'Universal' { | |
$ADGroups.Universal.$SamAccountName = Get-ADGroupMember -Identity $SamAccountName | Select-Object -ExpandProperty SamAccountName | |
} | |
} | |
} | |
#endregion | |
#region Get Member Count AD Groups | |
$ADGroups.Keys | | |
ForEach-Object{ | |
$GroupScope = $_ | |
$ADGroups.$GroupScope.Keys | | |
ForEach-Object{ | |
[PSCustomObject]@{ | |
Group = $_ | |
GroupScope = $GroupScope | |
Count = @($ADGroups.$GroupScope.$_).Count | |
} | |
} | |
} | |
#endregion | |
#region Get Security Matrix for Global AD Groups | |
$htUsers = @{} | |
$htProps = @{} | |
$ADGroups.Global.Keys | ForEach-Object {$htProps.$_ = $null} | |
foreach ($group in $ADGroups.Global.keys){ | |
foreach ($user in $ADGroups.Global.$($group)){ | |
if (!$htUsers.ContainsKey($user)){ | |
$htProps.SamAccountName = $user | |
$htUsers.$user = $htProps.Clone() | |
} | |
($htUsers.$user).$($group) = 'x' | |
} | |
} | |
$htUsers.GetEnumerator() | | |
ForEach-Object{ | |
[PSCustomObject]$($_.Value) | |
} | | |
Out-GridView | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment