Managing Windows Local Groups with PowerShell
-
As with local users, we can manage local groups with PowerShell in a "PowerShell way" today. The commands for managing local users are part of the LocalAccounts commandlet, the same one that we use for managing local users.
It is important to note that these commandlets are not part of PowerShell proper and are not available in all PowerShell versions. Also, while this is the "PowerShell way" to do user management, older methods like the net commands are stand alone utilities and work equally well from PowerShell as from any other calling method.
List Local Groups
Get-LocalGroupGet Details of Specific Local Group
Get-LocalGroupMember -Name administratorsAdd Local User to a Local Group
Add-LocalGroupMember -Group administrators -Member sallyor you can have a comma delimited list of users...
Add-LocalGroupMember -Group administrators -Member sally, john, buck, mack, hank, bettyAdd an Active Directory Domain User to a Local Group
Add-LocalGroupMember -Group administrators -Member "mydomain\roberta"Create a New Local Group
New-LocalGroup -Name mynewgroupDelete a Local Group
Remove-LocalGroup -Name mynewgroupRename a Local Group
Rename-LocalGroup -Name mynewgroup -NewName myrenamedgroup
Part of a series on Windows Systems Administration by Scott Alan Miller