半夜写脚本scripting
马上近100台server过来,要建帐号,估计得我写脚本了,只好把它写完了,没来得及优化
Dim arrFileLines() ,n
i = 0
Const ForReading = 1
strInputFile="C:\BAU_Users.txt"
Set FSO=CreateObject("Scripting.FileSystemObject")
Set objFile=FSO.OpenTextFile(strInputFile,ForReading)
' get local computer name
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
' Create pcAnywhere_users group
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("group")
' check if local group already exists
For Each objGroup In colAccounts
If objGroup.Name = pcAnywhere_users Then
intExists = 2
End If
Next
Set objGroup = colAccounts.Create("group", "pcAnywhere_users")
objGroup.SetInfo
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
loop
objFile.Close
' specify account to create
For n = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
strAccount =arrFileLines(n)
strPswd = "viso1234"
' check if local account already exists
intExists = 0
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
If objUser.Name = strAccount Then
intExists = 1
End If
Next
If intExists = 0 and n <9 Then
' create local user
Set objUser = colAccounts.Create("user", strAccount)
' set pswd
objUser.SetPassword strPswd
objUser.SetInfo
' Must change pswd next login
objUser.PasswordExpired = 1
objUser.SetInfo
' add to local admins group
Set objGroup = GetObject("WinNT://" & strComputer & _
"/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
objGroup.Add(objUser.ADsPath)
' Add to pcAnywhere_users group
Set objGroup = GetObject("WinNT://" & strComputer & _
"/pcAnywhere_users,group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
objGroup.Add(objUser.ADsPath)
else
Set objUser = colAccounts.Create("user", strAccount)
' set pswd
objUser.SetPassword strPswd
objUser.SetInfo
' Must change pswd next login
objUser.PasswordExpired = 1
objUser.SetInfo
' Add to pcAnywhere_users group
Set objGroup = GetObject("WinNT://" & strComputer & _
"/pcAnywhere_users,group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strAccount & _
",user")
objGroup.Add(objUser.ADsPath)
End If
Next
历史评论
暂无保留的历史评论。
评论为旧站历史记录,本站不再接受新评论。