Posted by adminjb Tue 6th Mar 2007 20:29 - Syntax is VisualBasic - 45 views
Download | New Post | Modify | Hide line numbers
  1.  
  2. Option Explicit
  3. Dim objFSO, strFileName, strContainerDN, objFile
  4. Dim objContainer, objGroup, strGroupName, intCount
  5. Const GROUP_TYPE_BUILTIN = &H00000001
  6. Const GROUP_TYPE_GLOBAL = &H00000002
  7. Const GROUP_TYPE_LOCAL = &H00000004
  8. Const GROUP_TYPE_UNIVERSAL = &H00000008
  9. Const GROUP_TYPE_SECURITY = &H80000000
  10. If Wscript.Arguments.Count <> 1 Then
  11.   Wscript.Echo "Syntax error"
  12.   Wscript.Echo _
  13. "cscript //nologo CreateGroups.vbs c:\MyFolder\Groups.txt"
  14.   Wscript.Quit
  15. End If
  16. strContainerDN = "ou=BAUD_GRP,dc=home,dc=baud,dc=cz"
  17. strFileName = Wscript.Arguments(0)
  18. Set objFSO = CreateObject("Scripting.FileSystemObject")
  19. On Error Resume Next
  20. Err.Clear
  21. Set objFile = objFSO.OpenTextFile(strFileName, 1)
  22. If Err.Number <> 0 Then
  23.   Err.Clear
  24.   Wscript.Echo "File not found: " & strFileName
  25.   Wscript.Quit
  26. End If
  27. Err.Clear
  28. Set objContainer = GetObject("LDAP://" & strContainerDN)
  29. If Err.Number <> 0 Then
  30.   Err.Clear
  31.   Wscript.Echo "Container not found: " & strContainerDN
  32.   Wscript.Quit
  33. End If
  34. On Error GoTo 0
  35. intCount = 0
  36. Do Until objFile.AtEndOfStream
  37.   strGroupName = objFile.ReadLine
  38.   If strGroupName <> "" Then
  39.     Set objGroup = objContainer.Create("group", _
  40.       "cn=" & strGroupName)
  41.     objGroup.Put "sAMAccountName", strGroupName
  42.     objGroup.Put "groupType", GROUP_TYPE_LOCAL _
  43.       Or GROUP_TYPE_SECURITY
  44.     On Error Resume Next
  45.     Err.Clear
  46.     objGroup.SetInfo
  47.     If Err.Number <> 0 Then
  48.       Err.Clear
  49.       Wscript.Echo "Unable to create group " & strGroupName
  50.     Else
  51.       intCount = intCount + 1
  52.     End If
  53.     On Error GoTo 0
  54.   End If
  55. Loop
  56. 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

 

Comments: 0