Skip to content

Instantly share code, notes, and snippets.

@josephkern
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save josephkern/e4d1e8a426ff45cce461 to your computer and use it in GitHub Desktop.

Select an option

Save josephkern/e4d1e8a426ff45cce461 to your computer and use it in GitHub Desktop.

Revisions

  1. josephkern revised this gist Aug 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get-ADMemberOf.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function Get-ADMemberOf {
    # A fast and accurate way of dertermining all of the groups
    # A fast and accurate way of determining all of the groups
    # one or more users are part of, especially useful when the groups are nested.

    # Example:
  2. josephkern renamed this gist Aug 5, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. josephkern revised this gist Aug 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get-MemberOf.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function Get-MemberOf {
    function Get-ADMemberOf {
    # A fast and accurate way of dertermining all of the groups
    # one or more users are part of, especially useful when the groups are nested.

  4. josephkern revised this gist Aug 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get-MemberOf.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    function Get-MemberOf {
    # A fast and accurate way of dertermining all of the groups
    # a user is part of, especially useful when the groups are nested.
    # one or more users are part of, especially useful when the groups are nested.

    # Example:
    # import-module ActiveDirectory
  5. josephkern created this gist Aug 5, 2015.
    28 changes: 28 additions & 0 deletions Get-MemberOf.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    function Get-MemberOf {
    # A fast and accurate way of dertermining all of the groups
    # a user is part of, especially useful when the groups are nested.

    # Example:
    # import-module ActiveDirectory
    # get-aduser <username> | Get-MemberOf | ft

    param(
    [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
    [string]$DistinguishedName
    )

    begin {}
    process {
    $tokens = get-aduser -SearchScope Base -SearchBase $DistinguishedName -Properties tokengroups -LDAPFilter '(objectClass=user)'

    $tokens.tokengroups | % {

    $objectProperties = @{ "GroupName" = $_.Translate([System.Security.Principal.NTAccount]);
    "SamAccountName" = $tokens.SamAccountName }

    New-Object -TypeName PSObject -Property $objectProperties

    }
    }
    end {}
    }