Get LocalGroup - PowerShell
Overview
Get-LocalGroup retrieves information about local groups on the computer. These groups manage user and computer accounts, and can be used to assign permissions and control access to resources.
Syntax
Get-LocalGroup [-Name] <string[]> [-Domain <string>] [-GroupCategory <string>] [-Filter <string>] [-Users <string[]>] [-Properties <string[]>] [-ErrorAction <ActionPreference>] [-WarningAction <ActionPreference>] [-InformationAction <ActionPreference>] [-Verbose] [-Debug] [-ErrorVariable <string>] [-WarningVariable <string>] [-InformationVariable <string>] [-OutVariable <string>] [-OutFile <string>] [-EA <ActionPreference>] [-WA <ActionPreference>] [-IA <ActionPreference>]
Options/Flags
- -Name: Specifies the name of the local group to retrieve information about.
- -Domain: Specifies the domain of the local group to retrieve information about. By default, the command retrieves information about local groups on the current computer.
- -GroupCategory: Specifies the category of the local group to retrieve information about. Valid categories include: Security, Distribution, Domain Local.
- -Filter: Specifies a filter to apply to the results. The filter can be any valid PowerShell expression.
- -Users: Specifies a list of users to retrieve information about. The command will retrieve information about the local groups that the specified users are members of.
- -Properties: Specifies a list of properties to retrieve for each local group. The default properties that are retrieved are: Name, Description, GroupCategory.
- -ErrorAction, -WarningAction, -InformationAction: Specifies the action to take when an error, warning, or information message is encountered. Valid values are: Continue, Stop, SilentlyContinue.
Examples
Example 1: Get information about the local group named “Administrators”.
Get-LocalGroup -Name Administrators
Example 2: Get information about all local groups in the “Security” category.
Get-LocalGroup -GroupCategory Security
Example 3: Get information about all local groups that the user “John Doe” is a member of.
Get-LocalGroup -Users "John Doe"
Common Issues
- Error: The local group could not be found. This error can occur if the specified local group does not exist.
- Warning: The local group is not in the correct domain. This warning can occur if the specified local group is in a different domain than the current computer.
- Information: The local group has no members. This information message can occur if the specified local group has no members.
Integration
Get-LocalGroup can be used with other PowerShell commands to perform advanced tasks. For example, the following command retrieves the members of the local group “Administrators” and exports them to a CSV file:
Get-LocalGroup -Name Administrators | Select-Object -ExpandProperty Members | Export-Csv -Path C:\Temp\Administrators.csv