Re: Listing Users that are Part of the Local Administrator Group



RayRay wrote:

> I'm trying to find/write a script that can return the members of the Local
> Administrator group on Win 2K/XP machines. I have an active directory
2003
> domain environment and basically want to be able to generate a text file
that
> lists the computers in my domain with the Domain users that belong to
those
> computers' local Administrator group. Very new to Windows scripting, and
I
> can't figure out how to pull the users from the local administrator group.
> I'm thinking I need to use WMI which is new to me as well. Any help is
most
> appreciated.

I've used a script similar to below to document the local Administrators
group on a PC remotely:

Option Explicit
Dim objGroup, strComputer

strComputer = "Delaware"

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Wscript.Echo "Members of local Administrators group on computer " &
strComputer
Call EnumGroup(objGroup, "")

Sub EnumGroup(objGroup, strOffset)
Dim objMember
For Each objMember In objGroup.Members
Wscript.Echo strOffset & objMember.Name & " (" & objMember.Class &
")"
If (objMember.Class = "Group") Then
Call EnumGroup(objMember, strOffset & "--")
End If
Next
End Sub

The program documents all members of the group, local and domain, users and
groups. The recursive subroutine handles group nesting, so it reveals
everyone with admin rights on the machine. The variable strOffset indents
the output to show the heirarchy of any nesting. This snippet could be
modified to loop through all computer objects in AD. For example, using the
same subroutine as above:

Option Explicit
Dim objDomain, objComputer, objGroup

Wscript.Echo "Members of local Administrators group on each computer"
Set objDomain = GetObject("WinNT://MyDomain")
objDomain.Filter = Array("computer")
For Each objComputer In objDomain
On Error Resume Next
Set objGroup = GetObject("WinNT://" & objComputer.Name &
"/Administrators,group")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Computer: " & objComputerName & " - Not available"
Else
On Error GoTo 0
Wscript.Echo "Computer: " & objComputer.Name
Call EnumGroup(objGroup "--")
End If
Next

The error trapping is needed to handle any computers not running. You would
run the script at a command prompt with the cscript host and redirect the
output to a text file. If the VBScript is called DocumentLocalAdmins.vbs:

cscript //nologo DocumentLocalAdmins.vbs > report.txt

A final refinement is to use Torgeir Bakken's IsConnectible function to ping
each computer before attempting to bind to the group object. This prevents
the long timeout if the machine is unavailable. That code, plus Torgeir's
similar code for this problem is at this link:

http://groups-beta.google.com/group/microsoft.public.windowsxp.wmi/browse_thread/thread/87807ab58dc0ee3a/366e0daf1e8bca65?q=IsConnectible+group:microsoft.public.*+author:Torgeir+author:Bakken&rnum=7&hl=en#366e0daf1e8bca65

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: Startup Script Via GPO... Where Are Parameters Stored?
    ... If I am setting up a startup script in a gpo, ... the local administrator passwords yourself remotely. ... Any computers that could not be ... by default members of "Domain Admins" are members. ...
    (microsoft.public.scripting.vbscript)
  • List Group Members in txt file problem
    ... I'm running this portion of a script to list the members of a group that are ... computers, there are over 1500 members, when I run it I dion't get all the ... Set FSO = CreateObject ...
    (microsoft.public.windows.server.scripting)
  • Re: Finding users in local admin groups
    ... > Here is a vbscript that you can run against a remote computer that moves ... > *local* users except 'Administrator) from the Administrators group to the ... You should also add to the script logging to a file of the ... > you moved on what computers. ...
    (microsoft.public.win2000.security)
  • Re: Change local administrator password ? through GPO or push script ?
    ... I would like to change the local administrator password of every computers member of my AD domain but I am not sure of the best method. ... Create a vbs script that points to the local computer and then deploy this script by GPO. ... This attribute will permit to know wich admin password is configured for this machine. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Not so Newbie
    ... The script is designed for situations like yours. ... wit 35+ computers and to go to each of those computers to individualy ... Prompt for an executable to run on each remote computer in the group. ... so you know where the deployment failed. ...
    (microsoft.public.windows.server.scripting)