?
Solved

Security Group VBScript

Posted on 2006-11-03
5
Medium Priority
?
613 Views
Last Modified: 2008-02-01
I have a script that doesn't seem to want to display the "description" text when rolling through my security groups. The basic concpet is to run this script and have it show the Dishtingushed Name, Common Name, Info and Description.

Anyone see a problem with why it errors out it hits the echo for the description field?

-------------------------------------------------------------------------------------------------------------
Option Explicit
      
Dim objCommand, objConnection, strBase, strFilter, strAttributes
Dim strQuery, objRecordset

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://ou=users,dc=domain,dc=com>"

strFilter = "(objectCategory=group)"
strAttributes = "distinguishedName,cn,info,description"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

'On Error Resume Next

Do Until objRecordSet.EOF
Wscript.Echo "Distinguished Name: " & objRecordSet.Fields("distinguishedName").value
Wscript.Echo "Common Name: " & objRecordSet.Fields("cn").value
Wscript.Echo "Information: " & objRecordSet.Fields("info").value
Wscript.Echo "Description: " & objRecordSet.Fields("description").value
objRecordSet.MoveNext
Loop
--------------------------------------------------------------------------------------------------------------

Thanks!
Flip
0
Comment
Question by:flipknob
[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
5 Comments
 
LVL 1

Author Comment

by:flipknob
ID: 17870424
I forgot to add that the line that contains:
"strBase = "<LDAP://ou=users,dc=domain,dc=com>" "

Isn't really reading the "users" OU. I just changed that to protect my AD.

Anyway, it's reading the security groups just fine aside fromt he description.

Sorry for confusing you even more. :)

Flip
0
 
LVL 6

Accepted Solution

by:
tone28 earned 200 total points
ID: 17870916
The description field for the group can hold a collection or array of values:

Option Explicit
     
Dim objCommand, objConnection, strBase, strFilter, strAttributes
Dim strQuery, objRecordset

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strBase = "<LDAP://ou=groups,dc=corp,dc=net>"

strFilter = "(objectCategory=group)"
strAttributes = "distinguishedName,cn,info,description"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

'On Error Resume Next

Do Until objRecordSet.EOF
Wscript.Echo "Distinguished Name: " & objRecordSet.Fields("distinguishedName").value
Wscript.Echo "Common Name: " & objRecordSet.Fields("cn").value
Wscript.Echo "Information: " & objRecordSet.Fields("info").value
If VarType(objRecordSet.Fields("description").value) = 8204 Then
      Dim myArray      
      myArray = objRecordSet.Fields("description").value
      Dim index
      For index = 0 To UBound(myArray)
               WScript.echo "Description: " & myArray(index)
      Next      
Else
      WScript.echo "Description" & objRecordSet.Fields("description").value
End If

objRecordSet.MoveNext
Loop
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

765 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