Posted by adminjb Tue 6th Mar 2007 20:29 - Syntax is VisualBasic - 45 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
-
Option Explicit
-
Dim objFSO, strFileName, strContainerDN, objFile
-
Dim objContainer, objGroup, strGroupName, intCount
-
Const GROUP_TYPE_BUILTIN = &H00000001
-
Const GROUP_TYPE_GLOBAL = &H00000002
-
Const GROUP_TYPE_LOCAL = &H00000004
-
Const GROUP_TYPE_UNIVERSAL = &H00000008
-
Const GROUP_TYPE_SECURITY = &H80000000
-
If Wscript.Arguments.Count <> 1 Then
-
Wscript.Echo "Syntax error"
-
Wscript.Echo _
-
"cscript //nologo CreateGroups.vbs c:\MyFolder\Groups.txt"
-
Wscript.Quit
-
End If
-
strContainerDN = "ou=BAUD_GRP,dc=home,dc=baud,dc=cz"
-
strFileName = Wscript.Arguments(0)
-
Set objFSO = CreateObject("Scripting.FileSystemObject")
-
On Error Resume Next
-
Err.Clear
-
Set objFile = objFSO.OpenTextFile(strFileName, 1)
-
If Err.Number <> 0 Then
-
Err.Clear
-
Wscript.Echo "File not found: " & strFileName
-
Wscript.Quit
-
End If
-
Err.Clear
-
Set objContainer = GetObject("LDAP://" & strContainerDN)
-
If Err.Number <> 0 Then
-
Err.Clear
-
Wscript.Echo "Container not found: " & strContainerDN
-
Wscript.Quit
-
End If
-
On Error GoTo 0
-
intCount = 0
-
Do Until objFile.AtEndOfStream
-
strGroupName = objFile.ReadLine
-
If strGroupName <> "" Then
-
Set objGroup = objContainer.Create("group", _
-
"cn=" & strGroupName)
-
objGroup.Put "sAMAccountName", strGroupName
-
objGroup.Put "groupType", GROUP_TYPE_LOCAL _
-
Or GROUP_TYPE_SECURITY
-
On Error Resume Next
-
Err.Clear
-
objGroup.SetInfo
-
If Err.Number <> 0 Then
-
Err.Clear
-
Wscript.Echo "Unable to create group " & strGroupName
-
Else
-
intCount = intCount + 1
-
End If
-
On Error GoTo 0
-
End If
-
Loop
-
Wscript.Echo "Done, " & intCount & " groups created"
-
PermaLink to this entry https://pastebin.co.uk/11490
Posted by adminjb Tue 6th Mar 2007 20:29 - Syntax is VisualBasic - 45 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0