2011-09-28 30 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之間的上述行和將所述計算機添加到組中。