2011-09-28 90 views
1

我有以下VBS脚本,在为我工作的学校添加多个新计算机帐户时,它非常有帮助。我想知道是否有人可以修改脚本,以便它还可以将组添加到新创建的计算机帐户的“成员”选项卡中。由于计算机“VBS脚本的成员”

' Author Guy Thomas http://computerperformance.co.uk/ 
' Found at http://www.computerperformance.co.uk/vbscript/vbscript_computer_spreadsheet.htm 
' Version 1.2 - May 2010 
' ------------------------------------------------------' 
Option Explicit 
Dim strComputer, strOU, strSheet, intRow 
Dim objRootLDAP, objContainer, objComputer, objShell 
Dim objExcel, objSpread 

' -----------------------------------------------' 
' Important change OU= and strSheet to reflect your domain 
' -----------------------------------------------' 

strOU = "OU=New Computers,OU=Workstations,OU=123,OU=Site Based Computer Accounts ," ' Note the comma 
strSheet = "C:\Documents and Settings\257466\Desktop\Create Computer Accounts\Computer Accounts.xls" 

' Bind to Active Directory, Computers container. 
Set objRootLDAP = GetObject("LDAP://rootDSE") 
Set objContainer = GetObject("LDAP://" & strOU & _ 
objRootLDAP.Get("defaultNamingContext")) 

' Open the Excel spreadsheet 
Set objExcel = CreateObject("Excel.Application") 
Set objSpread = objExcel.Workbooks.Open(strSheet) 
intRow = 2 'Row 1 often containes headings 

' Here is the loop that cycles through the cells 
Do Until objExcel.Cells(intRow,1).Value = "" 
    strComputer = objExcel.Cells(intRow, 1).Value 

    ' Build the actual computer. 
    Set objComputer = objContainer.Create("Computer", _ 
    "cn=" & strComputer) 
    objComputer.Put "sAMAccountName", strComputer & "$" 
    objComputer.Put "userAccountControl", 4096 
    objComputer.SetInfo 
    intRow = intRow + 1 
Loop 
objExcel.Quit 

WScript.Quit 
+1

请问[此论坛帖子](http://www.tek-tips.com/viewthread.cfm?qid=1246185&page=1)有帮助吗? – 2011-09-29 08:46:19

回答

0

感谢来自Oracle认证专家的评论,我能想出以下所创建的计算机添加到组。

' Added section to add the computer to the group 
' Comment out with if not needed 
Dim objGroup, strGroup 
strGroup = "OU=New Computers,OU=Workstations,OU=123,dc=company,dc=com" 
Set objGroup = GetObject("LDAP://" & strGroup) 
objGroup.add objComputer.adspath 

只需将objComputer.SetInfo和intRow = intRow + 1之间的上述行和将所述计算机添加到组中。