Get Local Groups and Members Powershell Tool
Total Page:16
File Type:pdf, Size:1020Kb

Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
Get Local Groups and Members PowerShell Tool
The help information provided below can also be viewed by using the following syntax:
Get-Help Get-LocalGroupsandMembers –Full
Help Info
NAME
Get-LocalGroupsandMembers
SYNOPSIS
Retrieves a list of groups as well as a specified group's members from
local and remote computers
SYNTAX
Get-LocalGroupsandMembers [[-ComputerName]
DESCRIPTION
The "Get Local Groups and Members PowerShell Tool" is able to display a list of groups on either the local or remote computer along with a specified group's members. This tool requires PowerShell version
3.0. This tool has only one mandatory parameter which is the $GroupList parameter. If you just want to find the members of the "Administrators" group on the local computer, then you do not have to make Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 any specification for the -ComputerName or the -GroupName parameters since the local computer and the "Administrators" group has been set as the default values. If you want to get a list of members of the "Administrators" group from a remote computer, then you specify the remote computer name using the -ComputerName parameter, but again, you do not have to specify the "Administrators" group using the -GroupName parameter since that is the default value. This script will also attempt to detect if the
Administrators group has been renamed, and if so, it will target that group instead. This tool uses the
"System.DirectoryServices.AccountManagement" .Net namespace that was released with .Net
Framework 3.5. Since Windows PowerShell 3.0 requires the full installation of Microsoft .NET
Framework 4, this will not be a problem, just ensure that the "#Requires -Version 3.0" statement remains at the top of the script to be used as the primary detection method, assuming that the full .Net
Framework 4 version is installed.
PARAMETERS
-ComputerName
Used to query a single computer or multiple computers.
Required? false
Position? 1
Default value $env:COMPUTERNAME
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-GroupName
Used to specify the name of a group if the default Administrators Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 group is not desired.
Required? false
Position? 2
Default value Administrators
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-GroupList
A mandatory parameter used to display a list of all the local groups
on a local or remote computer. This parameter requires only a Yes or
No value.
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, see
about_CommonParameters
(http://go.microsoft.com/fwlink/?LinkID=113216).
Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 INPUTS
OUTPUTS
------EXAMPLE 1 ------
C:\PS>To get a list of the local groups and the members of the
Administrators group on the local computer:
Get-LocalGroupsandMembers -GroupList "Yes"
------EXAMPLE 2 ------
C:\PS>To NOT get a list of the local groups, but to get the members of the
Administrators group on the local computer:
Get-LocalGroupsandMembers -GroupList "No"
Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
------EXAMPLE 3 ------
C:\PS>To get a list of the local groups and get the members of another
group besides the default Administrators group on the local computer:
Get-LocalGroupsandMembers -GroupList "Yes" -GroupName "Group1"
------EXAMPLE 4 ------
C:\PS>To NOT get a list of the local groups, but to get the members of
another group besides the default Administrators group on the local
computer:
Get-LocalGroupsandMembers -GroupList "No" -GroupName "Group1"
Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
------EXAMPLE 5 ------
C:\PS>To get a list of the local groups and the members of the
Administrators group on a remote computer:
Get-LocalGroupsandMembers -ComputerName "Computer1" -GroupList "Yes"
------EXAMPLE 6 ------
C:\PS>To NOT get a list of the local groups, but to get the members of the
Administrators group on the remote computer:
Get-LocalGroupsandMembers -ComputerName "Computer1" -GroupList "No"
------EXAMPLE 7 ------Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
C:\PS>To get a list of the local groups and get the members of another
group besides the default Administrators group on a remote computer:
Get-LocalGroupsandMembers -ComputerName "Computer1" -GroupList "Yes"
-GroupName "Group1"
------EXAMPLE 8 ------
C:\PS>To NOT get a list of the local groups, but to get the members of
another group besides the default Administrators group on a remote
computer:
Get-LocalGroupsandMembers -ComputerName "Computer1" -GroupList "No"
-GroupName "Group1"
Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 ------EXAMPLE 9 ------
C:\PS>To get a list of the local groups and get the members of the
Administrators group on multiple computers:
Get-LocalGroupsandMembers -ComputerName @("Compute1", "Computer2",
"Computer3") -GroupList "Yes"
------EXAMPLE 10 ------
C:\PS>To get a list of the local groups and get the members of another
group besides the default Administrators group on multiple computers:
Get-LocalGroupsandMembers -ComputerName @("Compute1", "Computer2",
"Computer3") -GroupList "Yes" -GroupName "Group1"
or
Get-LocalGroupsandMembers -ComputerName (Get-Content -Path
"$env:TEMP\ComputerList.txt") -GroupList "Yes" -GroupName "Group1" Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
------EXAMPLE 11 ------
C:\PS>To get a list of the local groups and get the members of multiple
groups on the local computer:
Get-LocalGroupsandMembers -GroupList "Yes" -GroupName @("Group1",
"Group2", "Group3")
or
Get-LocalGroupsandMembers -GroupList "Yes" -GroupName (Get-Content -Path
"$env:TEMP\GroupList.txt")
------EXAMPLE 12 ------
C:\PS>To get a list of the local groups and get the members of multiple Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 groups on multiple computers:
Get-LocalGroupsandMembers -ComputerName @("Compute1", "Computer2",
"Computer3") -GroupList "Yes" -GroupName @("Group1", "Group2", "Group3")
or
Get-LocalGroupsandMembers -ComputerName (Get-Content -Path
"$env:TEMP\ComputerList.txt") -GroupList "Yes" -GroupName (Get-Content
-Path "$env:TEMP\GroupList.txt")
------EXAMPLE 13 ------
C:\PS>To get a list of the local groups and get the members of multiple
groups on multiple computers and output the info to a .log (or .txt file)
while displaying the results on screen:
Get-LocalGroupsandMembers -ComputerName @("Compute1", "Computer2",
"Computer3") -GroupList "Yes" -GroupName @("Group1", "Group2", "Group3") |
Tee-Object -Filepath "$env:TEMP\ListofGroupsandMembers.log" Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014
or
Get-LocalGroupsandMembers -ComputerName (Get-Content -Path
"$env:TEMP\ComputerList.txt") -GroupList "Yes" -GroupName (Get-Content
-Path "$env:TEMP\GroupList.txt") | Tee-Object -Filepath
"$env:TEMP\ListofGroupsandMembers.txt"
------EXAMPLE 14 ------
C:\PS>To get a list of the local groups and get the members of multiple
groups on multiple computers and output the info to a .log (or .txt file)
while NOT displaying the results on screen:
Get-LocalGroupsandMembers -ComputerName @("Compute1", "Computer2",
"Computer3") -GroupList "Yes" -GroupName @("Group1", "Group2", "Group3") |
Out-File -FilePath "$env:TEMP\ListofGroupsandMembers.log"
or
Get-LocalGroupsandMembers -ComputerName (Get-Content -Path Author: Ron Ratzlaff (aka “The_Ratzenator”) Date: 8\26\2014 "$env:TEMP\ComputerList.txt") -GroupList "Yes" -GroupName (Get-Content
-Path "$env:TEMP\GroupList.txt") | Out-File -FilePath
"$env:TEMP\ListofGroupsandMembers.txt"
RELATED LINKS