For me, when starting to write a script, I usually want to isolate a my object down to the subset of what I want to perform my task on. So I might start with something like this:
Get-adcomputer -filter * -properties *| Where-Object {$_.operatingsystem -like “*server*” }|Select-object name
This is what I use to get all the servers in my small environment based on the operating system property having the work “Server” in it and then isolating the name. But over time I have found an easier way to do this.
(get-adcomputer -filter * -properties *| Where-Object {$_.operatingsystem -like “*server*” }).name
By simply putting the property you want on the outside of the parentheses, you get the same result without having to use Select-Object This is my simple way of visually representing what I am isolating, and starting out that was very helpful.
Another way to do this once an object has been created is simply stating your object dot property, like this:
$object.name
or for another property
$object.favoritecolor
One thing to keep in mind though is that you now have a set of objects with only one property, the Name. This can be tough when you are moving to the next cmdlet and although they both have the Name property, it fails. This is because you have stripped all the other properties away by either of the above 2 methods.
So if you want to isolate a property but keep the objects in tact, you can use
get-adcomputer -filter * -properties *|Select-object -expandproperty name
This was something that took me some time to grasp so hopefully this helps.
