expandproperty issue

Hello folks,

I am using Powershell version 3 at the moment. (but this may need to run in powershell version 2 as well).

Trying to get versioninfo to show the FileName, FileVersion, ProductVersion across a directory recursively.
but I also want the creationtime (or maybe in the future other properties to show).

While you can only use -expandproperty on 1 entity, i thought we could combine
it with -property and choose others. The results to return, but no ‘creationtime’ is shown.
It’s as if it’s being ignored.

I searched and I think my answer may lie with a custom psobject? Any hints would be great.
See my example code below.

get-childitem  -Path 'c:\temp*' -recurse            | 
Where-Object { $_.Attributes -ne 'Directory' } | 
Select-Object -Property creationtime  -expandproperty versioninfo 

You want a custom property. Maybe several. You can’t use -Property and -Expand at the same time. Honestly, I’m a little surprised the cmdlet isn’t wired to complain about that.

… | Select -Prop CreationTime,Name,Whatever,Else,@{n=‘my-name’,e={$.versioninfo.something}},@{n=‘my-name2’,e={$.versioninfo.somethingelse}}

You need to make a custom property for each hunk of VersionInfo that you want included. To be clear, there’s no magic, “expand VersionInfo into five properties and attach them all;” you need to do that yourself. I’ve done two pseudo-ones.

Thanks Don,

Took your advise and came up with this. I avoided the select-object and use format-table.

get-childitem  -Path $Path -recurse                 | 
Where-Object { $_.Attributes -ne 'Directory' }      | 
Format-Table CreationTime,@{n='filename';e={$_.versioninfo.filename}},@{n='fileversion'

This give me what i want. Thank you so much!

Note: Interesting that adding a -auto to the end of my format-table mysteriously removed my last column to show?

I try to do most filtering as early in the pipeline as possible. Here I would use the -file with Get-ChildItem to remove the need for the ‘Where…’ line:

$Path = '.\'
Get-ChildItem  -Path $Path -Recurse -File |
    Format-Table CreationTime,