Set LocalGroup - PowerShell
Overview
Set-LocalGroup
allows management of local groups on a computer system. It empowers users to create, modify, or delete local groups, add or remove members, and set group properties such as description and display name. The command is extensively used for user and group management in Windows environments, especially when automating administrative tasks with scripts.
Syntax
Set-LocalGroup [-Credential <PSCredential>] [-Description <string>] [-DisplayName <string>]
[-Group <Group>] [-Member <string []>] [-Name <string>] [-PassThru] [-State <GroupState>]
[-Type <GroupType>]
Options/Flags
-
-Credential
: Credential for connecting to the remote computer. -
-Description
: Description of the group. -
-DisplayName
: Display name of the group. -
-Group
: Name of the group to manage. -
-Member
: List of members to add or remove from the group. -
-Name
: Name of the group to create or modify. -
-PassThru
: Returns the modified group object. -
-State
: State of the group: Active, Disabled, or LockedOut. -
-Type
: Type of the group: Security, Distribution, or Universal.
Examples
Create a new local group:
Set-LocalGroup -Name "NewGroup"
Add a member to an existing group:
Set-LocalGroup -Group "ExistingGroup" -Member "NewMember"
Set the description of a group:
Set-LocalGroup -Name "TargetGroup" -Description "Updated Description"
Lockout a group:
Set-LocalGroup -Name "AdminGroup" -State LockedOut
Change the display name of a group:
Set-LocalGroup -Name "RemoteDesktopUsers" -DisplayName "Remote Users"
Remove a member from a group:
Set-LocalGroup -Group "SupportGroup" -Member "RemovedMember" -RemoveMember
Common Issues
- Access denied: Ensure you have sufficient privileges to manage local groups.
- Group not found: Verify that the group name specified exists.
- Member already exists: The specified member is already a member of the group.
- Invalid state: The specified state for the group is not valid.
- Type mismatch: The specified type for the group is not supported.
Integration
Set-LocalGroup
can be integrated into scripts and automation workflows for advanced group management tasks. For example, you can use it with Get-LocalGroup
to retrieve information about groups, or with New-LocalGroup
to create multiple groups in one operation.
Related Commands
Get-LocalGroup
: Gets local groups on a computer.Add-LocalGroupMember
: Adds members to a local group.Remove-LocalGroupMember
: Removes members from a local group.