Solved

Adding Domain group to local administrators groups on multiple servers

Posted on 2009-07-13
4
1,079 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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.

749 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