Solved

Adding Domain group to local administrators groups on multiple servers

Posted on 2009-07-13
4
1,081 Views
Last Modified: 2012-05-07
I need to add a domain group to the local administrators group on several servers by reading the server names from a text or csv file. Can someone point me to a vbs script for this? Using GPO isn't an option.
0
Comment
Question by:Woftt
[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
  • 2
4 Comments
 
LVL 27

Expert Comment

by:bluntTony
ID: 24841567
If you say that a GPO is not an option because you only want it to apply to a specific list of servers...

Instead of having a text file or csv with the server names, create a security group and make those servers members. Then use security filtering so that the GPO only applies to that security group.

The policy you want to use is a Restricted Groups policy.
0
 

Author Comment

by:Woftt
ID: 24841616
Thanks but AD is managed by a different group than the servers. Any AD changes would require and act of congress. So I really need a VB script.
0
 
LVL 2

Accepted Solution

by:
djdk74 earned 50 total points
ID: 24858728
Try this script. You will need to add your server names to the arrComputers in the format demonstrated in the code so it is not 100% what you are looking for but it should get the job done. Also you will need to modify the domain\group in strCommand to your domain and group name as demonstrated in the script.


arrComputers = Array("Server1","Server2","Server3")
 
For Each strComputer In arrComputers
strCommand = "cmd.exe /c net localgroup Administrators /add " & Chr(34) & "domain\group" & Chr(34)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
Next
Wscript.echo "Complete"

Open in new window

0
 

Author Comment

by:Woftt
ID: 24858933
Kind of answered my own question. The following code will do the trick.  Change the domain group to match your group and then change oTextFile to point to a text file with your list of servers or pc's
Const ForReading = 1
 
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oNet = CreateObject("wscript.network")
 
sDomain = oNet.UserDomain
sDomainGroup = "DOMAIN GROUP HERE"
sLocalGroup = "Administrators"
 
Set oTextFile = oFS.OpenTextFile("C:\servers.txt", ForReading)
 
Do While oTextFile.AtEndOfStream <> True
	sComputer = oTextFile.ReadLine
	
	Set oDomainGroup = GetObject("WinNT://" & sDomain & "/" & sDomainGroup & ",group")
	Set oLocalGroup = GetObject("WinNT://" & sComputer & "/" & sLocalGroup & ",group")
	
	oLocalGroup.Add(oDomainGroup.AdsPath)
 
Loop

Open in new window

0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Invest in your employees with these five simple steps to improve employee engagement and retention.
There’s a movement in Information Technology (IT), and while it’s hard to define, it is gaining momentum. Some call it “stream-lined IT;” others call it “thin-model IT.”
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

691 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