Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > List users in local administrators group on remote machine

Reply
Thread Tools Display Modes

List users in local administrators group on remote machine

 
 
Nick
Guest
Posts: n/a

 
      10-10-2008
Hi,

I am looking to manage all desktops on our network with regard to the local
administrators group. There are several things I am looking to accomplish:

1. list all users (domain and local) in local administrators group on
multiple remote computers
2. remove user from local administrators group on remote computer
3. add domain user account to local administrators group on remote
computer
4. remove local user account from remote computer
5. Report on current members of the local administrators group.

Any assistance you can provide would be greatly appreciated.
We have .Net software if that would be the best way to tackle this but I am
not sure which way to go.

Thanks!
Nick

 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      10-10-2008

"Nick" <> wrote in message
news:0E9F1D7C-E802-4E55-9935-...
> Hi,
>
> I am looking to manage all desktops on our network with regard to the
> local
> administrators group. There are several things I am looking to
> accomplish:
>
> 1. list all users (domain and local) in local administrators group on
> multiple remote computers
> 2. remove user from local administrators group on remote computer
> 3. add domain user account to local administrators group on remote
> computer
> 4. remove local user account from remote computer
> 5. Report on current members of the local administrators group.
>
> Any assistance you can provide would be greatly appreciated.
> We have .Net software if that would be the best way to tackle this but I
> am
> not sure which way to go.
>
> Thanks!
> Nick


You could do the whole lot with the inbuilt net.exe command:
1. net localgroup administrators
2. net localgroup administrators nick /delete
3. net localgroup administrators Domainname\nick /add
4. net user %ComputerName%\nick /delete
5. Same as 1. above.

To run the commands on a remote computer, put them into a batch file, then
invoke the batch file with psexec.exe (www.sysinternals.com) under your
domain admin account.


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-10-2008
Nick wrote:

>
> I am looking to manage all desktops on our network with regard to the
> local
> administrators group. There are several things I am looking to
> accomplish:
>
> 1. list all users (domain and local) in local administrators group on
> multiple remote computers
> 2. remove user from local administrators group on remote computer
> 3. add domain user account to local administrators group on remote
> computer
> 4. remove local user account from remote computer
> 5. Report on current members of the local administrators group.
>
> Any assistance you can provide would be greatly appreciated.
> We have .Net software if that would be the best way to tackle this but I
> am
> not sure which way to go.


I have an example VBScript program that enumerates all members of local
Administrators group linked here:

http://www.rlmueller.net/Enumerate%20Local%20Group.htm

The program handles membership due to nested local and domain groups. In
VBScript you use the WinNT provider with local objects. To add and/or remove
users (or groups) from a local group use code similar to below. With the
steps that check for direct membership (does not reveal membership due to
group nesting), you may not need to enumerate membership:
=========
' Specify NetBIOS name of computer.
strComputer = "Test001"

' Specify NetBIOS name of domain.
strDomain = "MyDomain"

' Bind to local Administrators group on remove computer.
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

' Add a local user to the group.
' Check first if they are already a direct member.
Set objLocalUser = GetObject("WinNT://" & strComputer" & "/JimSmith,user")
If (objGroup.IsMember(objLocalUser.AdsPath) = False) Then
objGroup.Add objLocalUser.AdsPath
End If

' Add a domain user to the group.
' Check first if they are already a direct member.
Set objDomainUser = GetObject("WinNT://" & strDomain & "/JimSmith,user")
If objGroup.IsMember(objDomainUser.AdsPath) = False) Then
objGroup.Add objDomainUser.AdsPath
End If

' Remove local user from group.
' Check first that they are a direct member.
Set objLocalUser = GetObject("WinNT://" & strComputer" & "/RogerJones,user")
If (objGroup.IsMember(objLocalUser.AdsPath) = True) Then
objGroup.Remove objLocalUser.AdsPath
End If

' Remove domain user from group.
Set objDomainUser = GetObject("WinNT://" & strDomain & "/RogerJones,user")
' Check first that they are a direct member.
If objGroup.IsMember(objDomainUser.AdsPath) = True) Then
objGroup.Remove objDomainUser.AdsPath
End If
==========
All of this can be one remotely, as long as your account is a member of the
local Administrators group. By default the group Domain Admins is a member
of the local Adminstrators group when the computer is joined to the domain.

You can read NetBIOS computer names from a text file and code similar to
above in a loop. In brief:
=========
Const ForReading = 1
' Specify text file of NetBIOS names of computers.
strFile = "c:\Scripts\Computers.txt"

' Open file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Read names from file.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Process this computer.
' ...
End If
Loop

' Clean up.
objFile.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Nick
Guest
Posts: n/a

 
      10-10-2008
Pegasus,

Thank you very much for your quick reply. I am new at this so can you give
me a short example of the command to use on remote machine with psexec.exe?
So if I understand I keep the PSEXEC.EXE on my machine and create a .bat file
and copy it to the remote machines and execute with PSEXEC.EXE.

Thanks,
Nick

"Pegasus (MVP)" wrote:

>
> "Nick" <> wrote in message
> news:0E9F1D7C-E802-4E55-9935-...
> > Hi,
> >
> > I am looking to manage all desktops on our network with regard to the
> > local
> > administrators group. There are several things I am looking to
> > accomplish:
> >
> > 1. list all users (domain and local) in local administrators group on
> > multiple remote computers
> > 2. remove user from local administrators group on remote computer
> > 3. add domain user account to local administrators group on remote
> > computer
> > 4. remove local user account from remote computer
> > 5. Report on current members of the local administrators group.
> >
> > Any assistance you can provide would be greatly appreciated.
> > We have .Net software if that would be the best way to tackle this but I
> > am
> > not sure which way to go.
> >
> > Thanks!
> > Nick

>
> You could do the whole lot with the inbuilt net.exe command:
> 1. net localgroup administrators
> 2. net localgroup administrators nick /delete
> 3. net localgroup administrators Domainname\nick /add
> 4. net user %ComputerName%\nick /delete
> 5. Same as 1. above.
>
> To run the commands on a remote computer, put them into a batch file, then
> invoke the batch file with psexec.exe (www.sysinternals.com) under your
> domain admin account.
>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      10-10-2008
Have a look at the ouput from "psexec.exe /?". It tells you everything you
need to know! Here is a simple example, taken straight from that screen. It
relies on you keeping your batch file in a central location, which is much
simpler than copying it to all machines.

psexe.exe \\SomePC -u DomainName\Nick -p NicksPassword
\\YourServer\SomeShare\SomeFolder\YourBatchfile.ba t

If you want psexec.exe to deal with several machines then you should have a
look at the "@file" parameter of psexec.exe.


"Nick" <> wrote in message
news:AF88B727-7B15-4C26-8A2E-...
> Pegasus,
>
> Thank you very much for your quick reply. I am new at this so can you
> give
> me a short example of the command to use on remote machine with
> psexec.exe?
> So if I understand I keep the PSEXEC.EXE on my machine and create a .bat
> file
> and copy it to the remote machines and execute with PSEXEC.EXE.
>
> Thanks,
> Nick
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Nick" <> wrote in message
>> news:0E9F1D7C-E802-4E55-9935-...
>> > Hi,
>> >
>> > I am looking to manage all desktops on our network with regard to the
>> > local
>> > administrators group. There are several things I am looking to
>> > accomplish:
>> >
>> > 1. list all users (domain and local) in local administrators group on
>> > multiple remote computers
>> > 2. remove user from local administrators group on remote computer
>> > 3. add domain user account to local administrators group on remote
>> > computer
>> > 4. remove local user account from remote computer
>> > 5. Report on current members of the local administrators group.
>> >
>> > Any assistance you can provide would be greatly appreciated.
>> > We have .Net software if that would be the best way to tackle this but
>> > I
>> > am
>> > not sure which way to go.
>> >
>> > Thanks!
>> > Nick

>>
>> You could do the whole lot with the inbuilt net.exe command:
>> 1. net localgroup administrators
>> 2. net localgroup administrators nick /delete
>> 3. net localgroup administrators Domainname\nick /add
>> 4. net user %ComputerName%\nick /delete
>> 5. Same as 1. above.
>>
>> To run the commands on a remote computer, put them into a batch file,
>> then
>> invoke the batch file with psexec.exe (www.sysinternals.com) under your
>> domain admin account.
>>
>>
>>



 
Reply With Quote
 
Nick
Guest
Posts: n/a

 
      10-10-2008
Thanks!!! That's great. I appreciate your help.

"Pegasus (MVP)" wrote:

> Have a look at the ouput from "psexec.exe /?". It tells you everything you
> need to know! Here is a simple example, taken straight from that screen. It
> relies on you keeping your batch file in a central location, which is much
> simpler than copying it to all machines.
>
> psexe.exe \\SomePC -u DomainName\Nick -p NicksPassword
> \\YourServer\SomeShare\SomeFolder\YourBatchfile.ba t
>
> If you want psexec.exe to deal with several machines then you should have a
> look at the "@file" parameter of psexec.exe.
>
>
> "Nick" <> wrote in message
> news:AF88B727-7B15-4C26-8A2E-...
> > Pegasus,
> >
> > Thank you very much for your quick reply. I am new at this so can you
> > give
> > me a short example of the command to use on remote machine with
> > psexec.exe?
> > So if I understand I keep the PSEXEC.EXE on my machine and create a .bat
> > file
> > and copy it to the remote machines and execute with PSEXEC.EXE.
> >
> > Thanks,
> > Nick
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "Nick" <> wrote in message
> >> news:0E9F1D7C-E802-4E55-9935-...
> >> > Hi,
> >> >
> >> > I am looking to manage all desktops on our network with regard to the
> >> > local
> >> > administrators group. There are several things I am looking to
> >> > accomplish:
> >> >
> >> > 1. list all users (domain and local) in local administrators group on
> >> > multiple remote computers
> >> > 2. remove user from local administrators group on remote computer
> >> > 3. add domain user account to local administrators group on remote
> >> > computer
> >> > 4. remove local user account from remote computer
> >> > 5. Report on current members of the local administrators group.
> >> >
> >> > Any assistance you can provide would be greatly appreciated.
> >> > We have .Net software if that would be the best way to tackle this but
> >> > I
> >> > am
> >> > not sure which way to go.
> >> >
> >> > Thanks!
> >> > Nick
> >>
> >> You could do the whole lot with the inbuilt net.exe command:
> >> 1. net localgroup administrators
> >> 2. net localgroup administrators nick /delete
> >> 3. net localgroup administrators Domainname\nick /add
> >> 4. net user %ComputerName%\nick /delete
> >> 5. Same as 1. above.
> >>
> >> To run the commands on a remote computer, put them into a batch file,
> >> then
> >> invoke the batch file with psexec.exe (www.sysinternals.com) under your
> >> domain admin account.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
No users in Local Administrators Group am Windows Vista Security 2 01-23-2009 04:10 PM
Domain Users in Local Machine Administrators Group MikeD Windows Small Business Server 2 05-03-2006 09:37 AM
list the users in local administrators group Ahmed Samy Scripting 1 11-22-2005 07:44 AM
local machine administrators group SYaroslav Windows Server 3 01-19-2005 09:10 PM
VBS script to list members of local administrators group Sandra L Miller Scripting 2 02-17-2004 11:14 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59