# pricing estimate System.DirectoryServices.ResultPropertyCollection

I'm missing out on something below :

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher.Filter = ("(objectclass=computer)")$computers = $objSearcher.findall()  So the inquiry is why do both adhering to results vary? $computers | %{
"Server name in quotes $_.properties.name" "Server name not in quotes " +$_.properties.name
}
PS> $computers[0] | %{"$_.properties.name"; $_.properties.name} System.DirectoryServices.SearchResult.properties.name GORILLA  0 2019-12-02 03:04:02 Source Share Answers: 3 I think it concerns the manner in which PS inserts details in the "". Attempt this : "Server name in quotes$ ($_. buildings). name" Or you might also require another set of$ (). I'm not someplace that I can examine it at now.

0
2019-12-03 04:45:55
Source

Close - - The listed below jobs appropriately, yet I would certainly be interested if any person has a much deeper description.

PS C:\> $computers[0] | %{ "$_.properties.name"; "$($_.properties.name)" }
System.DirectoryServices.SearchResult.properties.name
GORILLA


So presumably that $_. properties.name does not submission like I anticipated it to. If I'm envisioning effectively, the reality that the name building is multivalued creates it to return an array. Which (I assume) would certainly clarify why the adhering to jobs : $computers[0] | %{ $_.properties.name[0]}  If "name" were a string this needs to return the first personality, yet due to the fact that it is an array it returns the first team. 0 2019-12-03 04:45:29 Source When you consisted of$_. properties.name in the string, it was returning the type name of the building. When a variable is consisted of in a string and also the string is reviewed, it calls the ToString method on that particular object referenced by the variable (not consisting of the participants defined after).

In this instance, the ToString method is returning the type name . You can compel the analysis of the variable and also participants comparable to what EBGreen recommended, yet by utilizing

"Server name in quotes $($_.properties.name)"


In the various other circumstance PowerShell is reviewing the variable and also participants defined first and afterwards including it to the previous string.

You are appropriate that you are coming back a collection of buildings. If you pipeline \$ computer system [0 ]. buildings to get - participant, you can discover the object version right from the command line.

The integral part is listed below.

TypeName : System.DirectoryServices.ResultPropertyCollection

Name MemberType Definition

Values Property System.Collections.ICollection Values get ;

0
2019-12-03 04:13:26
Source