([adsisearcher] "(&(objectCategory=person))").FindAll()
This returns two rows for each record: path (a string) and properties (a ResultPropertyCollection):([adsisearcher] "(&(objectCategory=person))").FindAll() | select -first 1 | gm
TypeName: System.DirectoryServices.SearchResult
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetDirectoryEntry Method adsi GetDirectoryEntry()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Path Property System.String Path {get;}
Properties Property System.DirectoryServices.ResultPropertyCollection Properties {get;}
To explore the members of the Properties you can use a variety of approaches. Here are two I like:- Select -ExpandProperty cn - if you want the specific property CN for each ResultPropretyCollection
- Foreach-Object {$_.properties.CN} - this returns the same value by passing each ResultPropertyCollection to an enumerator, and retrieving the property from the properties.
Both approaches work fine, and, each has its strengths and weaknesses depending one what you are trying to do. Remember, if you use select, the new type returned from the cmdlet is a PSCustomObject.
0 comments:
Post a Comment