Understanding System.DirectoryServices.ResultPropertyValueCo

by Lembasts at 2012-12-17 19:42:35

I have some code searching AD which works fine using the [adsisearcher] type:

$ComputerObjects = $Search.FindAll()

$filtercomp = $ComputerObjects |

% {
New-Object PsObject -Property @{
WhenCreated=Get-Date ($
.Properties[‘whencreated’][0]) -Format d
PasswordLastSet=Get-Date ([datetime]::FromFileTime($.Properties[‘pwdlastset’][0])) -Format d
LastLogonTimeStamp=Get-Date ([datetime]::FromFileTime($
.Properties[‘lastlogontimestamp’][0])) -Format d

What I dont understand is why I need to get the first element of each property. For example, when I code:

I get the result : System.DirectoryServices.ResultPropertyValueCollection

When I look at the first element :

I get the string computer name. What is contained in the other elements? Why is the ad search data presented in this way? what exactly is System.DirectoryServices.ResultPropertyValueCollection?
by coderaven at 2012-12-17 21:22:02
That is just the way it works and those that have been using the ADSI searcher know that it has a few oddities. Just like the property names [‘name’], [‘whenchanged’], etc; must be in lower case. As soon better tools became available like the ActiveDirectory module and QAD tools we left the base .Net DS classes behind. Since you can install the ADWS on 2003 domain controllers and it comes on 2008 and up, there is no need to use the ADSI searcher unless you know how to work with it or just prefer it.
by Lembasts at 2012-12-17 22:38:25
Thanks. Sadly our organisation will not countenance installing ADWS on 2003 DCs and they will not install 2008 R2 DCs as they dont work with NT4 Trusts. Yes we sadly still have NT4 Trusts and cannot get rid of them in the foreseeable future. So I cannot even use the AD cmdlets! But thanks for letting me know that its an oddity and the code looks awful but thats just the way it is. I’ll live with it. Ill just start writing my own cmdlets/advanced functions to hide the mess.