Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find local administrator username 1

Status
Not open for further replies.

itd17

IS-IT--Management
Jan 24, 2002
84
0
0
US
What is the quickest way to find the username of the local admin account on my servers? I know most of them are Administrator, but some have been changed and I don't have time to connect to them individually.

Thanks
 
If I remember this correctly, they also have a more or less similar SID, so a script should be able to find this.
 
The script below should do the job - it finds the lcoal administrator name based on the SID. It is scripted to run on the local machine at the moment but you can modify it to run on multiple machines as you wish.

Code:
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colAccounts = objWMIService.ExecQuery _
    ("Select * From Win32_UserAccount Where LocalAccount = TRUE")

For Each objAccount in colAccounts
    If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then
        Wscript.Echo objAccount.Name
    End If
Next

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Thank you very much for the script. One more question. If I create a txt file with all my servers, how can I inject that into the script?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top