Solved

Security Group VBScript

Posted on 2006-11-03
5
611 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 50 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

Independent Software Vendors: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 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