Remove-ADGroupMember

Remove one or more members from an Active Directory group.

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

Key
   -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 ADGroup
       An Active Directory group object by providing one of the following values.
       (The identifier in parentheses is the LDAP display 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

   -Members ADPrincipal[]
A set of user, group, and computer objects in a comma-separated list to add to a group. To identify each object, use one of the following property values. Note: The identifier in parentheses is the LDAP display name.

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

Objects must be to this parameter directly, not via the pipeline.

For example passing a user and a group object variable:

-Members $userObject, $groupObject

The objects specified for this parameter are processed as Microsoft.ActiveDirectory.Management.ADPrincipal objects. Derived types, such as the following are also received by this parameter.
Microsoft.ActiveDirectory.Management.ADUser
Microsoft.ActiveDirectory.Management.ADComputer
Microsoft.ActiveDirectory.Management.ADServiceAccount
Microsoft.ActiveDirectory.Management.ADGroup
-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. The rules for determining the default value are given below. Note that rules listed first are evaluated first and once a default value can be determined, no further rules will be evaluated. In AD DS environments, a default value for Partition will be set in the following cases: - If the Identity parameter is set to a distinguished name, the default value of Partition is automatically generated from this distinguished name. - If running cmdlets from an AD provider drive, the default value of Partition is automatically generated from the current path in the drive. - If none of the previous cases apply, the default value of Partition will be set to the default partition or naming context of the target domain. In AD LDS environments, a default value for Partition will be set in the following cases: - If the Identity parameter is set to a distinguished name, the default value of Partition is automatically generated from this distinguished name. - If running cmdlets from an Active Directory provider drive, the default value of Partition is automatically generated from the current path in the drive. - If the target AD LDS instance has a default naming context, the default value of Partition will be set to the default naming context. To specify a default naming context for an AD LDS environment, set the msDS-default NamingContext property of the AD directory service agent (DSA) object (nTDSDSA) for the AD LDS instance. - If none of the previous cases apply, the Partition parameter will not take any default value. -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) -Confirm Prompt for confirmation before executing the command. -WhatIf Describe what would happen if you executed the command without actually executing the command. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.

Remove-ADGroupMember removes one or more users, groups, service accounts, or computers from an AD group.

The -Identity parameter specifies the AD group that contains the members to remove. 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, or pass a group object through the PowerShell pipeline. For example, use Get-ADGroup to retrieve a group object and then pass the object through the pipeline to Remove-ADGroupMember.

The -Members parameter specifies the users, computers and groups to remove from the group specified by the -Identity parameter. Identify a user, computer or group by its distinguished name (DN), GUID, security identifier (SID), or Security Accounts Manager (SAM) account name. Alternatively specify a user, computer, and group object variable. To specify more than one new member, use a comma-separated list. You cannot pass user, computer, or group objects through the pipeline to this cmdlet. To remove user, computer, or group objects from a group by using the pipeline, use Remove-ADPrincipalGroupMembership.

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.

Examples

Remove the user with samAccountName 'FredB' from the group 'SS64Group':

PS C:\> remove-adgroupmember -Identity "SS64Group" -Member "FredB"

Remove the users with samAccountNames 'administrator' and 'FredB' from the group 'SS64Group':

PS C:\> remove-adgroupmember "SS64Group" "administrator","Wilson Pais"

Remove the user with DistinguishedName 'CN=FredB,DC=AppNC' from the 'SS64Group' group on an AD LDS instance using the pipeline:

PS C:\> get-adgroup -server localhost:60000 "CN=SS64Group,DC=AppNC" | remove-adgroupmember -member "CN=FredB,
DC=AppNC"

“Will you, won't you, will you, won't you, will you join the dance?” ~ Lewis Carroll

Related:

Get-ADGroup - Get an AD group
Add-ADGroupMember - Add one or more members to an AD group
Remove-ADPrincipalGroupMembership - Remove a member from one or more AD groups


© Copyright SS64.com 1999-2014
Some rights reserved