When you run commands in PowerShell like Get-ADComputer it returns objects. While a text representation of those objects are displayed on the screen, that is just a representation not the full object. In your first case you piped the objects to Select-Object and specifically asked for the Name property of the object although there are many other properties available. Instead of piping to Select-Object, pipe the output to Get-Member and you can see all the available properties for the objects it returns. I suspect you want to filter the results based on the name property and a regular expression. In your foreach loop however, you are comparing the entire object (even though at this point it only has a name property since that is what you selected) against the regular expression. You would need to de-reference the object with the dot operator ($line.name -match $regex). Just to make things a little cleaner, I would write it this way:
[quote quote=269141]Use the -ExpandProperty parameter with Select-Object.
[/quote]
Looks like Matt beat me to the punch. ExpandProperty will work as because instead of returning a custom object with a Name property that you would have to reference with the property de-reference operator (dot), it will return just the string value of that property.