expandproperty issue

Welcome Forums General PowerShell Q&A expandproperty issue

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #66529

    Points: 2
    Rank: Member

    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 
  • #66532

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

    • #66544

      Points: 2
      Rank: Member

      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?

  • #66586

    Points: 176
    Helping Hand
    Rank: Participant

    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,

The topic ‘expandproperty issue’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort