Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS script cannot find AD group

Posted on 2012-03-15
2
Medium Priority
?
494 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 85

Accepted Solution

by:
oBdA earned 2000 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

721 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