Skip to content

Instantly share code, notes, and snippets.

@irwins
Created September 28, 2017 05:16
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/52c5fc7219e25f95e859cb235318b68c to your computer and use it in GitHub Desktop.
Save irwins/52c5fc7219e25f95e859cb235318b68c to your computer and use it in GitHub Desktop.
$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