Add-ADGroupMember

Add one or more members to an Active Directory group.

Syntax
      Add-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.

Add-ADGroupMember adds one or more users, groups, service accounts, or computers as new members of an AD group.

The -Identity parameter specifies the AD group that receives the new members. 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 the Get-ADGroup cmdlet to get a group object and then pass the object through the pipeline to Add-ADGroupMember.

The -Members parameter specifies the new members to add to a group. Identify a new member by its distinguish ed name (DN), GUID, security identifier (SID) or SAM account name. Alternatively specify user, computer, and group object variables. 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 add user, computer, or group objects to a group by using the pipeline, use Add-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 AD directory service agent (DSA) object (nTDSDSA) for the AD LDS instance.

Examples

Adds the user accounts with SamAccountNames User01 and User02 to the group SS64Group:

PS C:\> Add-ADGroupMember SS64Group User01,User02

Get a group from the Organizational Unit "OU=SS64,DC=AppNC" in the AD LDS instance localhost:60000 that has the name "VIPs" and then pipe it to Add-ADGroupMember, to add the user account with DistinguishedName: "CN=PJHARVEY,OU=SS64,DC=AppNC"

PS C:\> Get-ADGroup -Server localhost:60000 -SearchBase "OU=SS64,DC=AppNC" _
-filter { name -like "VIPs" } | Add-ADGroupMember -Members "CN=PJHARVEY,OU=SS64,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
Remove-ADGroupMember - Remove one or more members from an AD group


© Copyright SS64.com 1999-2013
Some rights reserved