Solved

Security Group VBScript

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 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