How to delete the local group from the windows system using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To delete the local group from the windows system using PowerShell, you need to use the RemoveLocalGroup command as shown below.

Remove-LocalGroup -Name TestGroup

In the above example, the local group name TestGroup will be removed from the local system. To remove the local group from the remote systems, we can use Invoke-Command as shown in the below example.

Invoke-Command -ComputerName Test1-Win2k12,Test1-Win2k16 -ScriptBlock
{Remove-LocalGroup -Name TestGroup}

Remove-Localgroup command is supported from the PowerShell version 5.1 onwards and this command is a part of Microsoft.PowerShell.LocalAccounts module. If you have the PS version 5.1 or the local accounts module not available then you can use the cmd command.

net localgroup testgroup /delete

Similarly, you can run the above command on the remote system using Invoke-Command method.

Invoke-Command -ComputerName Test1-Win2k12,Test1-Win2k16 -ScriptBlock{
   net localgroup TestGroup /delete
}
raja
Published on 02-Nov-2020 10:51:26
Advertisements