This is a (really) basic question… I have only just learnt to spell PowerShell.
It is a fundamental that is tripping me up… will seem like a simple matter, and I am looking more towards a conceptual answer.
“gci -file ! select Fullname, LastWriteTime | ft” will return the full filespec and the last modified date and time.
“gci -file ! select Fullname, LastWriteTime.year | ft” will return the full filespec and nothing else.
…but I can use LastWriteTime.year successfully in a script to give me the year a file was last updated.
What am I missing? (told you it was basic!)
Not 100% but Select-Object can only query properties (LastWriteTime) of a supplied object and not nested object properties. LastWriteTime is also an object with properties
You can either extract the year as you were (the more basic approach) or you can use a feature called calculated properties. Looks something like this
gci | select FullName, @{name="LastWriteYear";e={$_.LastWriteTime.year}
Thanks neemobeer (like the name)… and it works… but I’m not getting the concept of “nested object properties”.
The answer is good… I will keep it in mind as I get more experience and (hopefully) these concept pieces will fall into place. I will also play with “calculated properties” as a way to convince select that I am giving it what it wants/needs.
Cheers