Hi guys,

I try to read some attribute from AD, such as lastlogontimestamp.

When I run the script. the result is [complex object]

Is there a way that can output the correct result?

the script as below.

 Code:
$selectedProperties = "displayName,lastLogonTimestamp"
$propertynames = Split($selectedProperties,",")

$oCn = CreateObject("ADODB.Connection")
$oCmd = CreateObject("ADODB.Command")
$oCn.Provider = "ADsDSOObject"
$ = $oCn.Open("Active Directory Provider", "", "", -1)
$oCmd.ActiveConnection = $oCn
$oCmd.Properties("Page Size").Value = 1000
$oCmd.Properties("Searchscope").Value = 2 ;ADS_SCOPE_SUBTREE
$oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://contoso.com/CN=test,OU=Users,OU=test,DC=contoso,DC=com' WHERE objectCategory='user' ORDER BY Name"

$oRS = $oCmd.Execute
While Not $oRS.EOF 
	For $i = 0 to UBound($propertynames)
		If VarType($oRS.Fields($propertyNames[$i]).Value) = 9 Or VarType($oRS.Fields($propertyNames[$i]).Value) >= 8192
			?  "[Complex Object]"
		Else
			?  $oRS.Fields($propertyNames[$i]).Value
		EndIf
	Next
	$oRS.MoveNext
Loop 


Edited by Mart (2009-10-28 09:00 AM)
Edit Reason: Please use code tags when posting code.