Solved

VBS script cannot find AD group

Posted on 2012-03-15
2
481 Views
Last Modified: 2012-03-15
Hello,
I have a scripts that shows me all useraccounts that are member of an administrator group. When I ran it, it worked fine. I now have added an extra group:  Exchange Organization Administrators but I get the error: There is no such object on the server

This is the code

Option Explicit
Dim strMember, strDNSDomain, strContainer
Dim objGroup, objRootDSE
Dim arrMemberOf, arrMemberOf2, arrMemberOf3, arrMemberOf4
Dim strList, strList2, strList3, strList4, arrGroup

' Bind to Active Directory' 
strContainer = "cn=Administrators,cn=Builtin, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' Get the Builtin Administrators group
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo "Members of Administrator groups " & vbCrLf
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList = strList & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList

' Get the Domain Administrators group
strContainer = "cn=Domain Admins,cn=Users, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf2 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf2
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList2 = strList2 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList2

' Get the Enterprise Administrators group
strContainer = "cn=Enterprise Admins,cn=Users, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf3 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf3
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList3 = strList3 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList3

' Get the Exchange Administrators group
strContainer = "cn=Exchange Organization Administrators,cn=Microsoft Exchange Security Groups, "
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo

arrMemberOf4 = objGroup.GetEx("member")

' Loop = For Each .... Next 
WScript.Echo strContainer & vbCr
WScript.Echo "----------------------------------" & vbCrLf
   For Each strMember in arrMemberOf4
      strMember = Mid(strMember, 4, 330) 
      arrGroup = Split(strMember, "," )
      strList4 = strList4 & arrGroup(0) & " " & vbCrLf
   Next 
Wscript.Echo vbCr & strList4

Wscript.Quit

Open in new window


When I look in AD the group is there.
Thanks for any help
0
Comment
Question by:P-R-W
2 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
There's an error in line 64: "Microsoft Exchange Security Groups" is an Organizational Unit, not a container. The line should read
strContainer = "cn=Exchange Organization Administrators,ou=Microsoft Exchange Security Groups,"
0
 

Author Closing Comment

by:P-R-W
Comment Utility
Many thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Starting in Windows Server 2008, Microsoft introduced the Group Policy Central Store. This automatically replicating location allows IT administrators to have the latest and greatest Group Policy (GP) configuration settings available. Let’s expl…
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now