Solved

Security Group VBScript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

896 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

13 Experts available now in Live!

Get 1:1 Help Now