Solved

VBS script cannot find AD group

Posted on 2012-03-15
2
483 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 83

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

18 Experts available now in Live!

Get 1:1 Help Now