PoshCode Logo PowerShell Code Repository

Show-ADGroupMembership (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/684"></script>download | new post

This script uses the Quest AD cmdlets to retrieve AD Groups from an LDAP search root and maps their membership (shows nested groups using Doug Finke’s Show-NetMap scripts that leverage the Microsoft Research NetMap project. Improvements or suggestions welcomed!

  1. # Author: Steven Murawski http://www.mindofroot.com
  2. # This script requires the Show-NetMap script from Doug Finke and the NetMap files
  3. # These can be found at http://dougfinke.com/blog/?p=465
  4. #
  5. # Also required are the Quest AD Cmdlets.
  6.  
  7. #requires -pssnapin Quest.ActiveRoles.ADManagement
  8.  
  9. param([string]$SearchRoot= 'yourdomain.local/usersOU')
  10.  
  11. Function New-SourceTarget ($s,$t) {
  12.         New-Object PSObject |
  13.                 Add-Member -pass noteproperty source $s |
  14.                 Add-Member -pass noteproperty target $t
  15. }
  16.  
  17. $groups = Get-QADGroup -GroupType Security -SearchRoot $SearchRoot
  18.  
  19. [string[]]$GroupNames = $groups | foreach {$_.name}
  20.  
  21. $sources = @()
  22.  
  23. foreach ($group in $groups)
  24. {
  25.         $name = $group.name
  26.         foreach ($member in $group.members)
  27.         {
  28.                 $SubGroupName = $member -replace '^CN=(.+?),OU=.*', '$1'
  29.                 if ($GroupNames -contains $SubGroupName)
  30.                 {
  31.                         $sources += New-SourceTarget $SubGroupName $name
  32.                 }
  33.         }
  34.        
  35. }
  36.  
  37. . c:\scripts\powershell\Show-NetMap
  38.  
  39. $sources | Show-NetMap

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me