Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (51 sloc) 1.93 KB
Function Get-LocalAdmins {
Gets the members of the local administrators of the computer
and outputs the result to a CSV file.
.PARAMETER Computers
Specifies the Computer names of devices to query
System.String. Get-LocalAdmins can accept a string value to
determine the Computers parameter.
Get-LocalAdmins -Computers CL1,CL2
Get-LocalAdmins -Computers (Get-Content -Path "$env:HOMEPATH\Desktop\computers.txt")
Get-LocalAdmins -Computers DC,SVR8 | Format-Table -AutoSize -Wrap
Get-LocalAdmins -Computers DC,SVR8 | Export-Csv -Path "$env:HOMEPATH\Desktop\LocalAdmin.csv" -NoTypeInformation
Source script:
# testing the connection to each computer via ping before
# executing the script
foreach ($computer in $Computers) {
if (Test-Connection -ComputerName $computer -Quiet -count 1) {
$livePCs += $computer
} else {
Write-Verbose -Message ('{0} is unreachable' -f $computer) -Verbose
$list = new-object -TypeName System.Collections.ArrayList
foreach ($computer in $livePCs) {
$admins = Get-WmiObject -Class win32_groupuser -ComputerName $computer |
Where-Object {$_.groupcomponent -like '*"Administrators"'}
$obj = New-Object -TypeName PSObject -Property @{
ComputerName = $computer
LocalAdmins = $null
foreach ($admin in $admins) {
$null = $admin.partcomponent -match '.+Domain\=(.+)\,Name\=(.+)$'
$null = $matches[1].trim('"') + '\' + $matches[2].trim('"') + "`n"
$obj.Localadmins += $matches[1].trim('"') + '\' + $matches[2].trim('"') + "`n"
$null = $list.add($obj)
You can’t perform that action at this time.