Add LocalGroupMember - PowerShell


Overview

The Add-LocalGroupMember command allows you to add one or more user accounts or groups to a local group on the computer. This is useful for controlling access to resources and managing user privileges.

Syntax

Add-LocalGroupMember [-Group] <string> -Member <string[]> [-Verbose] [-Confirm] [-WhatIf] [<CommonParameters>]

Options/Flags

  • -Group: Specifies the name of the local group to add members to.
  • -Member: Specifies the user accounts or groups to add to the local group. You can specify multiple members separated by commas or pipe them in.
  • -Verbose: Provides detailed information about the operation, including the name of the added members and any errors that occur.
  • -Confirm: Prompts you to confirm the operation before it is executed.
  • -WhatIf: Simulates the operation without making any changes. Provides information about what would happen if the operation were executed.

Examples

Add a user to a local group:

Add-LocalGroupMember -Group "Administrators" -Member "JohnDoe"

Add multiple users to a local group:

Add-LocalGroupMember -Group "PowerUsers" -Member "JaneDoe","TomSmith"

Pipe user accounts from another command:

Get-LocalUser | Add-LocalGroupMember -Group "Users"

Common Issues

  • Ensure that the local group exists before attempting to add members.
  • Verify that the user accounts or groups you are adding have the correct permissions to join the local group.
  • If you receive an “Access is denied” error, ensure that you are running PowerShell as an administrator.

Integration

The Add-LocalGroupMember command can be combined with other PowerShell commands to automate user management tasks. For example, you can use the Get-LocalGroup command to retrieve a list of local groups and the Remove-LocalGroupMember command to remove members from a local group.

  • Get-LocalGroup
  • Remove-LocalGroupMember
  • Set-LocalGroup