Add-GroupMembers

Adds a users or groups to a local group.

Syntax

Add-GroupMembers [-Name] <String> [-Members] <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.

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String The group name. true false
Members 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-GroupMembers -Name Administrators -Members EMPIRE\DarthVader,EMPIRE\EmperorPalpatine,REBELS\LSkywalker

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

EXAMPLE 2

Add-GroupMembers -Name TieFighters -Members NetworkService

Adds the local NetworkService account to the local TieFighters group.