New LocalGroup - PowerShell


Overview

The New-LocalGroup cmdlet creates a new local group on the specified computer. Local groups are used to manage user and computer accounts on a local computer. They can be used to grant permissions to resources, such as files and folders, and to control access to applications and services.

Syntax

New-LocalGroup [-Name] <string> [-DisplayName] <string> [-Description] <string> [-GroupType] <int> [-Members] <string[]> [-Password] <SecureString> [-ProtectedFromAccidentalDeletion] [-Scope] <int> [-Credential] <PSCredential>

Options/Flags

| Option | Description | Default |
| ———– | ———– | ———– |
| -Name | Specifies the name of the new local group. | Required |
| -DisplayName | Specifies the display name of the new local group. | Optional |
| -Description | Specifies the description of the new local group. | Optional |
| -GroupType | Specifies the type of the new local group. The following values are valid: 2 (Security), 4 (Distribution). | Optional |
| -Members | Specifies the members of the new local group. | Optional |
| -Password | Specifies the password for the new local group. | Optional |
| -ProtectedFromAccidentalDeletion | Specifies whether the new local group is protected from accidental deletion. | False |
| -Scope | Specifies the scope of the new local group. The following values are valid: 0 (Local), 1 (Global), 2 (Universal). | Optional |
| -Credential | Specifies the credentials to use when creating the new local group. | Optional |

Examples

Create a new local security group named “MyGroup”

New-LocalGroup -Name "MyGroup"

Create a new local security group named “MyGroup” with a display name of “My Display Group” and a description of “This is my group”

New-LocalGroup -Name "MyGroup" -DisplayName "My Display Group" -Description "This is my group"

Create a new local distribution group named “MyGroup” with a list of members

New-LocalGroup -Name "MyGroup" -GroupType 4 -Members "user1", "user2", "user3"

Create a new local security group named “MyGroup” with a password

$password = ConvertTo-SecureString -String "MyPassword" -AsPlainText -Force
New-LocalGroup -Name "MyGroup" -Password $password

Common Issues

  • If the specified group name already exists, the command will fail with an error.
  • If the specified group type is not valid, the command will fail with an error.
  • If the specified members are not valid, the command will fail with an error.
  • If the specified password is not valid, the command will fail with an error.

Integration

The New-LocalGroup cmdlet can be used with other PowerShell cmdlets to manage local groups. For example, the following command creates a new local group named “MyGroup” and then adds the user “user1” to the group:

New-LocalGroup -Name "MyGroup"
Add-LocalGroupMember -Group "MyGroup" -Member "user1"