Solved

list local administrator group members.

Posted on 2014-09-09
18
252 Views
Last Modified: 2014-09-10
I need a command to list members in the local administrator group for a list of servers.  

Please advise.

Thanks.
0
Comment
Question by:nav2567
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +1
18 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40313292
simple command prompt (Assuming you have psexec)
for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c net localgroup Administrators

Open in new window

0
 

Expert Comment

by:Robert Bratton
ID: 40313310
You can use the PSEXEC.exe (Windows SysInternals) tool to run the net command on multiple servers:
psexec @serverfile.txt cmd "/c net localgroup administrators"

Open in new window

Just put a list of servernames in the serverfile.txt
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40313348
If you are looking for a PowerShell script then, Similar question is answered here.. Check and let me know if you have any trouble in getting report..
www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28505177.html
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:nav2567
ID: 40313618
I tried to pipe the results to a file by putting a  >>c:\result.txt at the end.

Is there a way I can display the server name before each result in the result file?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40313622
for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c hostname & net localgroup Administrators >> \\computer\c$\gmembers.txt
                                          

Open in new window


computer would be the name of the computer you are running the command from.
0
 

Author Comment

by:nav2567
ID: 40313636
becraig, I ran that line but still do not see the hostname in the gmembers.txt file.
0
 

Author Comment

by:nav2567
ID: 40313645
By the way, you will need %% instead of %.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40313646
hmm that sounds weird:

You only need %% if you run as a bat or cmd file, from the command line % is what you need (I did not see a need to save a one liner as a cmd or bat)

for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c echo ============================== & hostname &echo ============================== & net localgroup administrators >> \\computer\c$\gmembers.txt

Open in new window

0
 
LVL 40

Expert Comment

by:Subsun
ID: 40313651
Did you try the PS script?  It will give you a neat csv file which you can open in excel.
0
 

Author Comment

by:nav2567
ID: 40313668
sorry, becraig, I tried but still do not see hostname is being displayed in my results.txt.  Here is what I use:

for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c hostname & net localgroup Administrators >> c:\results.txt
0
 
LVL 29

Expert Comment

by:becraig
ID: 40313672
Then we can just repeat the variable, though I also see Subsun's report is a nice csv:

 for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c echo %a & net localgroup Administrators >> c:\results.txt 

Open in new window

0
 

Author Comment

by:nav2567
ID: 40314133
becraig,

It is still not good and same result.  The "echo %a" result did not get piped into the results.txt file but only being shown at the command prompt when I run it.

Subsun, I tried the PS script and the result file only contains information on the last server name in the list.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40314161
Try..
function get-localusers {
 param(
 [Parameter(Mandatory=$true,valuefrompipeline=$true)]
 [string]$strComputer
 )
 
 $Select = "Name","Class","Parent" | %{  
 Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember('$_', 'GetProperty', `$Null, `$_, `$Null) }}"
 }
 
 If (Test-Connection $strComputer -Count 2 -Quiet){
  try{
  $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
  $AdminGroup = $computer.psbase.children.find("Administrators")
  $Adminmembers= $AdminGroup.psbase.invoke("Members") | Select $Select
    foreach ($admin in $Adminmembers) {
    $admin | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"$(($_.parent -SPLIT "/")[-1])\$($_.Name)"}},Class,@{N="Parent";E={($_.parent -SPLIT "/")[-1]}}
    }
 }catch{ 
 "" | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"Access Denied"}},Class,Parent
 }
 }
Else {
 "" | Select @{N="ComputerName";E={$strComputer}},@{N="Administrators";E={"Not able to Ping"}},Class,Parent
 }
}
Get-Content "C:\Powershell\Servers.txt" | %{get-localusers $_} | Select ComputerName,Administrators,Class,Parent | Export-Csv "C:\Powershell\LocalAdm$((get-date).toString('MM-dd-yyyy')).csv" -NTI

Open in new window

1
 
LVL 29

Expert Comment

by:becraig
ID: 40314716
Lol my bad

for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c echo %a   \\%a\c$\result.txt & net localgroup Administrators >> 
\\%a\c$\result.txt
I suggest saving to the computer you're running from.  \\%a\c$\result.txt
0
 

Author Comment

by:nav2567
ID: 40314858
becraig,

You script is still not working as expected.  Can you please test it?
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40314880
@nav2567, Did you try the PS script which I posted in ID: 40314161? or are you looking only for a batch script?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40314993
for /f %a in (c:\serverlist.txt) do psexec \\%a cmd /c echo %a >>  \\%a\c$\result.txt & net localgroup Administrators >>
\\%a\c$\result.txt

Open in new window

0
 

Author Comment

by:nav2567
ID: 40315299
Sorry, becraig.  It is still not working.  I do not want to pipe the result to the servers C drive.  

I am going to have to use Subsun's script as it has the display I need.  

Thanks for your help.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question