Solved

Adding Domain group to local administrators groups on multiple servers

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
Synchronize a new Active Directory domain with an existing Office 365 tenant
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 tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now