< Back

Add-CGroupMember

Sun Jan 12, 2020 8:55 pm

NAME Add-CGroupMember



SYNOPSIS

Adds a users or groups to a *local* group.





SYNTAX

Add-CGroupMember [-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 <String>

The group name.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Member <String[]>

The users/groups to add to a group.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Add-CGroupMember -Name Administrators -Member EMPIRE\\DarthVader,EMPIRE\\EmperorPalpatine,REBELS\\LSkywalker



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









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Add-CGroupMember -Name TieFighters -Member NetworkService



Adds the local NetworkService account to the local TieFighters group.











RELATED LINKS