Solved

VBS script cannot find AD group

Posted on 2012-03-15
2
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 37724780
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
ID: 37724799
Many thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In-place Upgrading Dirsync to Azure AD Connect
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

752 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