How to create a new local group using PowerShell?


To create a new local group on the local or the remote system using PowerShell, we can use the NewLocalGroup command. 

Example

New-LocalGroup -Name "TestGroup" -Description "Test Group"

Output

Name       Description
----       -----------
TestGroup Test Group

You can verify it from the Computer Management GUI.

To create the local group on the remote systems, you can use Invoke-Command. For example,

Invoke-Command -ComputerName Test1-Win2k12,Test1-Win2k16 -ScriptBlock{
   New-LocalGroup -Name 'TestGroup' -Description 'New Test Group'
}

The above command will create a New Local group named ‘TestGroup’ on the remote systems, Test1-Win2k12, and Test1-Win2k16.

New-LocalGroup command is available in the module Microsoft.PowerShell.LocalAccounts which is part of the PowerShell version 5.1 or higher versions. If you have the older PowerShell version system then you can use the cmd command.

Net localgroup 'TestGroup2' /add

For the remote servers,

Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{
   Net Localgroup ‘TestGroup2’ /add
}

Updated on: 02-Nov-2020

691 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements