Get-ADPrincipalGroupMembership

Get-ADPrincipalGroupMembership is accessible with the help of addsadministration module. To install addsadministration on your system please refer to this link.

Synopsis

Gets the Active Directory groups that have a specified user, computer, group, or service account.

Description

The Get-ADPrincipalGroupMembership cmdlet gets the Active Directory groups that have a specified user, computer, group, or service account as a member. This cmdlet requires a global catalog to perform the group search. If the forest that contains the user, computer or group does not have a global catalog, the cmdlet returns a non-terminating error. If you want to search for local groups in another domain, use the ResourceContextServer parameter to specify the alternate server in the other domain.

The Identity parameter specifies the user, computer, or group object that you want to determine group membership for. You can identify a user, computer, or group object by its distinguished name (DN), GUID, security identifier (SID) or SAM account name. You can also specify a user, group, or computer object variable, such as $, or pass an object through the pipeline to the Identity parameter. For example, you can use the Get-ADGroup cmdlet to retrieve a group object and then pass the object through the pipeline to the Get-ADPrincipalGroupMembership cmdlet. Similarly, you can use Get-ADUser or Get-ADComputer to get user and computer objects to pass through the pipeline.

For AD LDS environments, the Partition parameter must be specified except in the following two conditions:

-The cmdlet is run from an Active Directory provider drive.

-A default naming context or partition is defined for the AD LDS environment. To specify a default naming context for an AD LDS environment, set the msDS-defaultNamingContext property of the Active Directory directory service agent (DSA) object (nTDSDSA) for the AD LDS instance.

Parameters

-AuthType 
         Specifies the authentication method to use. Possible values for this parameter include:

    Required?                    false
    Position?                    named
    Default value                Microsoft.ActiveDirectory.Management.AuthType.Negotiate
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Credential <PSCredential>
    Specifies the user account credentials to use to perform this task. The default credentials are the credentials of the currently logged on user unless the cmdlet is run from an Active Directory PowerShell provider drive. If the cmdlet is run from such a provider drive, the account associated with the drive is the default.

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Identity <ADPrincipal>
    Specifies an Active Directory principal object by providing one of the following property values. The identifier in parentheses is the LDAP display name for the attribute.

    Required?                    true
    Position?                    1
    Default value                
    Accept pipeline input?       True (ByValue)
    Accept wildcard characters?  false

-Partition <String>
    Specifies the distinguished name of an Active Directory partition. The distinguished name must be one of the naming contexts on the current directory server. The cmdlet searches this partition to find the object defined by the Identity parameter.

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-ResourceContextPartition <String>
    Specifies the distinguished name of the partition of an AD or AD LDS instance to search. Use this parameter with the ResourceContextServer parameter to specify a partition hosted by the specified server. If the ResourceContextPartition parameter is not specified, the default partition of the ResourceContextServer is searched.

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-ResourceContextServer <String>
    Specifies that the cmdlet return a list of groups that the user is a member of and that reside in the specified domain. Use this parameter to search for groups in a domain that is not the domain where the user's account resides. To search a partition other than the default partition in this domain, also specify the ResourceContextPartition parameter.

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

-Server <String>
    Specifies the Active Directory Domain Services instance to connect to, by providing one of the following values for a corresponding domain name or directory server. The service may be any of the following:  Active Directory Lightweight Domain Services, Active Directory Domain Services or Active Directory Snapshot instance.

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

Syntax

Get-ADPrincipalGroupMembership [-AuthType <ADAuthType>] [-Credential <PSCredential>] [-Identity] <ADPrincipal> [-Partition <String>] [-ResourceContextPartition <String>] [-ResourceContextServer <String>] [-Server <String>] [<CommonParameters>]

Notes
This cmdlet does not work with an Active Directory Snapshot.

————————– EXAMPLE 1 ————————–
C:\PS>get-adprincipalgroupmembership -server localhost:60000 -identity “CN=GirishKumar,DC=AppNC” -partition “DC=AppNC”
Retrieve all the groups the user ‘CN= GirishKumar ,DC=AppNC’ is a member of on an AD LDS instance.

————————– EXAMPLE 2 –————————-
C:\PS>get-adprincipalgroupmembership -Identity Administrator

distinguishedName : CN=Domain Users,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Domain Users
objectClass       : group
objectGUID        : 86c0f0d5-8b4d-4f35-a867-85a006b92902
SamAccountName    : Domain Users
SID               : S-1-5-23-3245234-234234545-2342342332-432

distinguishedName : CN=Administrators,CN=Builtin,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : DomainLocal
name              : Administrators
objectClass       : group
objectGUID        : 02ce3874-dd86-41ba-bddc-013f34019978
SamAccountName    : Administrators
SID               : S-1-5-33-23423

distinguishedName : CN=Schema Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Universal
name              : Schema Admins
objectClass       : group
objectGUID        : 8d62890f-385e-4cfa-9b2a-c72576097583
SamAccountName    : Schema Admins
SID               : S-1-5-21-123123464-23423412312-1984117282-234

distinguishedName : CN=Enterprise Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Universal
name              : Enterprise Admins
objectClass       : group
objectGUID        : 0215b0a5-aea1-40da-b598-720efe930ddf
SamAccountName    : Enterprise Admins
SID               : S-1-5-21-41432690-213412123123-23432423121-324

distinguishedName : CN=Domain Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Domain Admins
objectClass       : group
objectGUID        : 5ccc6037-c2c9-42be-8e92-c8f98afd0011
SamAccountName    : Domain Admins
SID               : S-1-5-21-324324324-32423423-13213432143-234

distinguishedName : CN=Group Policy Creator Owners,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Group Policy Creator Owners
objectClass       : group
objectGUID        : a58f7bf2-fd20-4bbd-96f0-ee10fa1613c7
SamAccountName    : Group Policy Creator Owners
SID               : S-1-4-21-234234324-3719764436-23432423-234

Retrieve all the groups the administrator is a member of.

————————– EXAMPLE 3 ————————–
C:\PS>get-adprincipalgroupmembership -Identity Administrator -ResourceContextServer ChildDomain.TOSSolution.Com -ResourceContextPartition “DC=TOSSolution,DC=com”

distinguishedName : CN=Domain Users,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Domain Users
objectClass       : group
objectGUID        : 86c0f0d5-8b4d-4f35-a867-85a006b92902
SamAccountName    : Domain Users
SID               : S-1-5-23-3245234-234234545-2342342332-432

distinguishedName : CN=Group Policy Creator Owners,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Group Policy Creator Owners
objectClass       : group
objectGUID        : a58f7bf2-fd20-4bbd-96f0-ee10fa1613c7
SamAccountName    : Group Policy Creator Owners
SID               : S-1-4-21-234234324-3719764436-23432423-234

distinguishedName : CN=Enterprise Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Universal
name              : Enterprise Admins
objectClass       : group
objectGUID        : 0215b0a5-aea1-40da-b598-720efe930ddf
SamAccountName    : Enterprise Admins
SID               : S-1-5-21-41432690-213412123123-23432423121-324

distinguishedName : CN=Schema Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Universal
name              : Schema Admins
objectClass       : group
objectGUID        : 8d62890f-385e-4cfa-9b2a-c72576097583
SamAccountName    : Schema Admins
SID               : S-1-5-21-123123464-23423412312-1984117282-234

distinguishedName : CN=Domain Admins,CN=Users,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : Global
name              : Domain Admins
objectClass       : group
objectGUID        : 5ccc6037-c2c9-42be-8e92-c8f98afd0011
SamAccountName    : Domain Admins
SID               : S-1-5-21-324324324-32423423-13213432143-234

distinguishedName : CN=Administrators,CN=Builtin,DC=TOSSolution,DC=com
GroupCategory     : Security
GroupScope        : DomainLocal
name              : Administrators
objectClass       : group
objectGUID        : 02ce3874-dd86-41ba-bddc-013f34019978
SamAccountName    : Administrators
SID               : S-1-5-33-23423

Retrieve all the groups the adminsitrator account in the local domain is a member of in the resource domain ChildDomain.TOSSolution.Com

You can check the Version, CommandType and Source of this cmdlet by giving below command.

Get-Command Get-ADPrincipalGroupMembership

Get-Command Get-ADPrincipalGroupMembership powershell script command cmdlet

You can also read about
. Add-ADGroupMember
. Add-ADPrincipalGroupMembership
. Get-ADComputer
. Get-ADGroup
. Get-ADGroupMember
. Get-ADUser
. Remove-ADGroupMember
. Remove-ADPrincipalGroupMembership

To know more PowerShell cmdlets(Commands) on addsadministration (Active Directory) click here

Click on this Link for an Single place where you get all the PowerShell cmdlet sorted based on the modules.

You can also refer other blogs on PowerShell at link

You can also refer other blogs on Microsoft at link

And also if you required any technology you want to learn, let us know below we will publish them in our site http://tossolution.com/

Like our page in Facebook and follow us for New technical information.

References are taken from Microsoft

Leave a Reply

Your email address will not be published. Required fields are marked *