Add-GroupMember

Adds a users or groups to a local group.

Syntax

Add-GroupMember [-Name] <String> [-Member] <String[]> [-WhatIf] [-Confirm] [<CommonParameters>]

Description

You would think it's pretty easy and straight-forward to add users/groups to a local group, but you would be wrong. The quick solution is to use net localgroup, but that won't accept user/group names longer than 24 characters. This means you have to use the .NET Directory Services APIs. How do you reliably add both users and groups? What if those users are in a domain? What if they're in another domain? What about built-in users? Fortunately, you're brain hasn't exploded.

So, this function adds users and groups to a local group.

If the members are already part of the group, nothing happens.

The user running this function must have access to the directory where each principal in the Member parameter and the directory where each of the group's current members are located.

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String

The group name.

true false
Member String[]

The users/groups to add to a group.

true false
WhatIf SwitchParameter false false
Confirm SwitchParameter false false
CommonParameters This cmdlet supports common parameters. For more information type
Get-Help about_CommonParameters.

EXAMPLE 1

Add-GroupMember -Name Administrators -Member EMPIRE\DarthVader,EMPIRE\EmperorPalpatine,REBELS\LSkywalker

Adds Darth Vader, Emperor Palpatine and Luke Skywalker to the local administrators group.

EXAMPLE 2

Add-GroupMember -Name TieFighters -Member NetworkService

Adds the local NetworkService account to the local TieFighters group.