Add-ADPrincipalGroupMembership

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

Syntax
      Add-ADPrincipalGroupMembership [-Identity] ADPrincipal
         [-MemberOf] ADGroup[] [-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 ADPrincipal
       An Active Directory user/group object, specified 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 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)

   -Confirm
       Prompt for confirmation before executing the command.

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

Add-ADPrincipalGroupMembership adds a user, group, service account, or computer as a new member to one or more AD groups.
If you are only adding to a single AD group you may prefer to use Add-ADGroupMember.

The -Identity parameter specifies the new user, computer, or group to add. 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 pipeline. For example, you can use Get-ADGroup to get a group object and then pass the object through the pipeline to Add-ADPrincipalGroupMembership . Similarly, you can use Get-ADUser or Get-ADComputer to get user and computer objects to pass through the pipeline.

This cmdlet collects all of the user, computer and group objects from the pipeline, and then adds these objects to the specified group by using one AD operation.

The -MemberOf parameter specifies the groups that receive the new member. Identify a group by its distinguished name (DN), GUID, security identifier (SID), or Security Accounts Manager (SAM) account name. Alternatively specify 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 add to a group by passing the group through the pipeline, use Add-ADGroupMember.

Examples

Add the user with SamAccountName "Darien1" to the group "SS64":

PS C:\> Add-ADPrincipalGroupMembership -Identity Darien1 -MemberOf SS64

Get all users with "SvcAccount" in their name and add them to the group "ServiceAccounts":

PS C:\> Get-ADUser -Filter 'Name -like "*SvcAccount*"' | Add-ADPrincipalGroupMembership -MemberOf ServiceAccounts

Get all the current members of "Old Group" and add those same members to the group "New Group":

PS C:\> Get-ADGroup -Identity 'Old Group' -Properties members -Verbose | select-object -Expandproperty members | Add-ADPrincipalGroupMembership -MemberOf 'New Group'

Add all employees in "Branch1" in the AD LDS instance "localhost:60000" whose title is "Account Lead" to the group with the DistinguishedName "CN=AccountLeads,OU=AccountsDept,DC=SS64":

PS C:\> Get-ADUser -Server localhost:60000 -SearchBase "DC=SS64" -filter { Title -eq "Account Lead" -and Office -eq
"Branch1" } | Add-ADPrincipalGroupMembership -MemberOf "CN=AccountLeads,OU=AccountsDeptOU,DC=SS64"

“You know it is not in my Interest to pay the Principal; nor is it my Principal to pay the Interest” ~ Richard Brinsley Sheridan

Related PowerShell Cmdlets

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


 
Copyright © 1999-2024 SS64.com
Some rights reserved