- 1 year ago
Windows PowerShell Command To List Group Members - Fine-Tuning
To list group members using Windows PowerShell, you can use the Get-ADGroupMember
cmdlet if you are working with Active Directory groups. Here's an example of the command:
powershellGet-ADGroupMember -Identity "GroupName" | Select-Object Name, SamAccountName, ObjectClass
In the command above, replace "GroupName"
with the name of the group for which you want to list the members. The Get-ADGroupMember
cmdlet retrieves the members of the specified group, and the Select-Object
cmdlet is used to choose and display specific properties of the group members, such as their Name, SamAccountName, and ObjectClass.
If you are not working with Active Directory and need to list members of a local group on a Windows machine, you can use the Get-LocalGroupMember
cmdlet. Here's an example:
powershellGet-LocalGroupMember -Group "GroupName" | Select-Object Name, PrincipalSource, ObjectClass
Replace "GroupName"
with the name of the local group for which you want to list the members. The Get-LocalGroupMember
cmdlet retrieves the members of the specified local group, and the Select-Object
cmdlet is used to choose and display specific properties of the group members, such as their Name, PrincipalSource, and ObjectClass.
By fine-tuning the Select-Object
cmdlet, you can choose different properties to display or format the output as per your requirements. You can explore additional properties available for group members by using the Get-Member
cmdlet on the output of Get-ADGroupMember
or Get-LocalGroupMember
.
Please note that working with Active Directory cmdlets (Get-ADGroupMember
) requires the Active Directory module to be installed, and the appropriate permissions are needed to query Active Directory.