Link to home
Create AccountLog in
Avatar of Mark Pavlak
Mark PavlakFlag for United States of America

asked on

Trouble reading Multi Valued Attributes from AD using VBS

I am currently working on a script which helps read particular AD account info and builds into a spread sheet.  One of the attributes I am trying to read is the protocolsettings attribute.  I know how to decode the results; however when multiple values exist ie


I only can get the 1st in the list.  How would I access the second and third.

I am using some the sub below.  note the objuser.protoclSettings call, when this is ran I would only get
HTTP§0§1§§§§§§ as the result I cannot grab the other two.

Sub ProcessOU (strOU)
Dim strNewOU,strObjectLocation
' Section to bind to ANY Active Directory.
Set objRoot = GetObject("LDAP://rootDSE")
Set ObjContainer = GetObject( strOU& _
For Each objUser In ObjContainer
	If objUser.class ="user" then
		objExcel.Cells(intRow,1)  = objUser.givenName
		objExcel.Cells(intRow,2)  =
		objExcel.Cells(intRow,3)  = objUser.description
		objExcel.Cells(intRow,4)  = objUser.physicalDeliveryOfficeName
		objExcel.Cells(intRow,5)  =
		objExcel.Cells(intRow,6)  = objuser.telephonenumber
		objExcel.Cells(intRow,7)  = objuser.title
		objExcel.Cells(intRow,8)  =
		objExcel.Cells(intRow,9)  = objuser.ipPhone
		objExcel.Cells (intRow,10)= objuser.protocolSettings
		If objuser.msNPAllowDialin = "True" Then
		objExcel.Cells(intRow,14) = "Allow Access"
		objExcel.Cells(intRow,14) = "Controll Access through RAS Policy"
		End If
intRow = intRow + 1
Else If objuser.Class = "organizationalUnit" Then
		'Wscript.Echo objUser.Name&" Is an OU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
		'WScript.Echo objUser.distinguishedName &"is the DN"
		strNewOU = Replace(objUser.distinguishedName,",DC=ELIZABETH",",")
		ProcessOU ("LDAP://"&strNewOU)
	End If
	End If
End Sub

Open in new window

Avatar of RobSampson
Flag of Australia image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Mark Pavlak


Thank you! I have a couple of questions though and one correction on your code.  I like to fully understand thing so could you explain line 20 to me.  This is also where I needed to make the correction though.  it should read

objSettings = objUser.GetEx("protocolSettings") inorder for the For statement to function properly.  But my question is what is the .GetEx method mean.  I understand what it is doing but I am looking more for its definition.
Hi, you're right about objSettings....good spotting....that was a cut and paste error, and I didn't get a chance to test it.

The GetEx method documentation can be found here:

Basically, this method makes sure that the correct data type is returned whether there are none, one, or multiple values in the multi-valued attribute, without returning an error, as direct access would if it didn't exist.

It returns a data type (determined by TypeName(objSettings)) of Empty, String, or Array.