Edit an AD principal (typically a user but can also be a group or computer) to remove a membership of one or more Active Directory groups.

      Remove-ADPrincipalGroupMembership [-Identity] ADPrincipal
         [-MemberOf] ADGroup[] [-AuthType {Negotiate | Basic}]
            [-Credential PSCredential] [-Partition string] [-PassThru]
               [-Server string] [-Confirm] [-WhatIf] [CommonParameters]

   -AuthType {Negotiate | Basic}
       The authentication method to use: Negotiate (or 0), Basic (or 1)
       A Secure Sockets Layer (SSL) connection is required for Basic authentication.

   -Credential PSCredential
       The user account credentials to use to perform this task.
       The default credentials are those 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.

       Type a user name, such as "User64" or "Domain64\User64" or specify a
       PSCredential object such as one generated by Get-Credential 

       If a user name is specified, the cmdlet will prompt for a password.

    -Identity ADPrincipal
       An Active Directory group object by providing one of the following values.
       (The identifier in parentheses is the LDAP provider name for the attribute.)

          Distinguished Name 
            Example: CN=AnnualReports,OU=europe,CN=users,DC=corp,DC=SS64,DC=com 
          GUID (objectGUID) 
            Example: 599c3d2e-f72d-4d20-8a88-030d99495f20
          Security Identifier (objectSid) 
            Example: S-1-5-21-3165297888-301567370-576410423-1103
          Security Accounts Manager (SAM) Account Name (sAMAccountName)
            Example: AnnualReports

       The cmdlet searches the default naming context or partition to find the object.
       If two or more objects are found, the cmdlet returns a non-terminating error.

       This parameter can also get this object through the pipeline or you can set this
       parameter to an object instance.

       This example shows how to set the parameter to a distinguished name.
          -Identity  "CN=AnnualReports,OU=europe,CN=users,DC=corp,DC=SS64,DC=com"

       This example shows how to set this parameter to a group object instance named "ADGroupInstance".
          -Identity $ADGroupInstance

   -MemberOf ADGroup[]
       The AD groups to add a user, computer, or group to as a member.
       You can identify a group by providing one of the following values.
       Note: The identifier in parentheses is the LDAP provider name for the attribute.

          Distinguished Name
            Example:  CN=MattJones,CN=Europe,CN=Users,DC=corp,DC=SS64,DC=com
          GUID (objectGUID)
            Example: 644c3d2e-f72d-4d20-8a68-030d91295f43
          Security Identifier (objectSid)
            Example: S-1-5-21-3165297888-301567370-576410423-1103
          SAM Account Name (sAMAccountName) 
            Example: mattjones

        If specifying more than one group, use commas to separate the groups in the list.

        The following example shows how to specify this parameter by using SAM account name values.
          -MemberOf "SaraDavisGroup", "JohnSmithGroup"
   -Partition string
       The distinguished name of an AD 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. 
       The following two examples show how to specify a value for this parameter.
          -Partition "CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"
          -Partition "CN=Schema,CN=Configuration,DC=EUROPE,DC=TEST,DC=SS64,DC=COM"
       In many cases, a default value will be used for the Partition parameter if no value
       is specified.

   -PassThru switch
       Return the new or modified object.
       By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output.
   -Server string
       The AD Domain Services instance to connect to, this may be a Fully qualified domain name,
       NetBIOS name, Fully qualified directory server name (with or without port number)

       Prompt for confirmation before executing the command.

       Describe what would happen if you executed the command without actually executing the command.

Remove-ADPrincipalGroupMembership removes a user, group, computer, service account, or any other account object from one or more AD groups.

The -Identity parameter specifies the user, group, or computer to remove. Identify the user, group, or computer by its distinguished name (DN), GUID, security identifier (SID) or SAM account name. Alternatively specify a user, group, or computer object variable, or pass an object through the PowerShell pipeline. For example, Get-ADUser to retrieve a user object and then pass the object through the pipeline to Remove-ADPrincipalGroupMembership. Similarly, you can use Get-ADGroup or Get-ADComputer to get group, service account and computer objects to pass through the pipeline.

This cmdlet collects all of the user, computer, service account and group objects from the pipeline, and then removes these objects from the specified group by using one Active Directory operation.

The -MemberOf parameter specifies the groups that you want to remove the member from. You can identify a group by its distinguished name (DN), GUID, security identifier (SID) or Security Accounts Manager (SAM) account name. Alternatively specify a group object variable. To specify more than one group, use a comma-separated list. You cannot pass group objects through the pipeline to the -MemberOf parameter. To remove a member from groups that are passed through the pipeline, use the Remove-ADGroupMember cmdlet.


Remove the user 'Darien Hsu' from the administrators group:

PS C:\> Remove-ADPrincipalGroupMembership -Identity "Darien Hsu " -MemberOf "Administrators"

Retrieve the user with DistinguishedName 'CN=JohnDoe,DC=AppNC' and remove it from the group with the DistinguishedName 'CN=SS64,DC=AppNC' using the pipeline:

PS C:\> get-aduser -server localhost:60000 -Identity "CN=JohnDoe,DC=AppNC" _
  | remove-adprincipalgroupmembership -memberof "CN=SS64,DC=AppNC"

“Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it's the only thing that ever has” ~ Margaret Mead

Related PowerShell Cmdlets

Add-ADPrincipalGroupMembership - Add a member to one or more AD groups.
Get-ADPrincipalGroupMembership - Get the AD groups that have a specified user, computer, or group.

Copyright © 1999-2023
Some rights reserved