Solved

Adding Domain group to local administrators groups on multiple servers

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
Read about why it is more lucrative for an IT company to participate in government projects.
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…
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 …

829 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