Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

  1. '
  2. ' Copyright (c) 1997-1999 Microsoft Corporation
  3. '
  4. ' This script lists the ADSI path to the user objects
  5. ' that a given group contains
  6. ' This is a routine that prints the users in a group
  7. Sub FindGroupMembership ( objService , theGroup )
  8. On Error Resume Next
  9. Dim objInstance
  10. Dim objEnumerator
  11. Dim groupFound
  12. groupFound = 0
  13. ' Enumerate the Group
  14. Set objEnumerator = objService.InstancesOf ( "ds_group" )
  15. If Err = 0 Then
  16. ' Go thru the groups looking for the correct one
  17. For Each objInstance In objEnumerator
  18. Dim propertyEnumerator
  19. Set propertyEnumerator = objInstance.Properties_
  20. If propertyEnumerator("DS_sAMAccountName") = theGroup Then
  21. groupFound = 1
  22. Wscript.Echo "Group: " + propertyEnumerator.Item("DS_sAMAccountName") + " has users:"
  23. For x = LBound(propertyEnumerator("DS_member")) To UBound(propertyEnumerator("DS_member"))
  24. Wscript.Echo propertyEnumerator("DS_member")(x)
  25. Next
  26. End If
  27. Next
  28. Else
  29. WScript.Echo "Err = " + Err.Number + " " + Err.Description
  30. End If
  31. If( groupFound = 0) Then
  32. Wscript.Echo "Group not found: " + theGroup
  33. End If
  34. End Sub
  35. ' Start of script
  36. ' Create a locator and connect to the namespace where the DS Provider operates
  37. Dim objLocator
  38. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  39. Dim objService
  40. Set objService = objLocator.ConnectServer(".", "root\directory\LDAP")
  41. ' Set the impersonation level
  42. objService.Security_.ImpersonationLevel = 3
  43. ' The first argument should be the group
  44. Set objArgs = Wscript.Arguments
  45. If objArgs.Count <> 0 Then
  46. FindGroupMembership objService , objArgs(0)
  47. Else
  48. Wscript.Echo "Usage: groupContains <group>"
  49. End If