Solved

Security Group VBScript

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

12 Experts available now in Live!

Get 1:1 Help Now