Remove LocalGroup - PowerShell


Overview

Remove-LocalGroup removes local groups from a target computer. Use this command to manage local groups as part of user account and group management tasks.

Syntax

Remove-LocalGroup [-Domain <string>] -Group <string> [-Credential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

Options/Flags

  • -Domain: Specifies the name of the domain controller or computer where the local group exists. If not specified, the local computer is used.
  • -Group: Specifies the name of the local group to remove. This parameter is required.
  • -Credential: Specifies a PSCredential object to use for authentication. By default, the current user’s credentials are used.
  • -WhatIf: Displays what would happen without actually executing the command.
  • -Confirm: Prompts for confirmation before executing the command.

Examples

Example 1: Remove a local group

Remove-LocalGroup -Group "MyLocalGroup"

Example 2: Remove a local group from a domain controller

Remove-LocalGroup -Domain "contoso.com" -Group "DomainLocalGroup"

Example 3: Remove a local group with confirmation

Remove-LocalGroup -Group "MyLocalGroup" -Confirm

Common Issues

  • Error: The local group does not exist: Ensure that the specified local group exists on the target computer.
  • Error: Access denied: Verify that the current user has sufficient permissions to remove local groups or provide appropriate credentials using -Credential.

Integration

Combine Remove-LocalGroup with other PowerShell commands, such as Get-LocalGroup, to manage and control local groups on multiple computers. For example:

$groups = Get-LocalGroup -ComputerName "Server1, Server2" | Where-Object { $_.Name -eq "MyLocalGroup" }
Remove-LocalGroup -Group $groups.Group