我有以下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
答案 0 :(得分: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之间,它就会将计算机添加到一个组中。