Select-Object -expandproperty SomeArray

Welcome Forums General PowerShell Q&A Select-Object -expandproperty SomeArray

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

3 years, 4 months ago.

  • Author
  • #29655

    Points: 0
    Rank: Member


    can anyone please tell me the short version of expanding values in an array (property with squiggly brackets and lots of values in it)?

    For example,
    Get-CompInfo -ComputerName MyPC | Select-Object -expandproperty DiskInfo

    How do I shorten the second part of the command after the pipe?

    I've seen someone do it somewhere in some video demo but I can't remember.

    Thank you very much

  • #29662

    Points: 0
    Rank: Member

    (Get-CompInfo -ComputerName MyPC).DiskInfo

  • #29671

    Points: 428
    Helping Hand
    Rank: Contributor

    Sean's example is a implicit loop, which requires Powershell v3 or higher. Rather than doing this:

    Get-CompInfo -ComputerName MyPC | foreach{$_.DiskInfo}

    the implicit foreach was provided as a shortcut to do the same thing.

  • #29678

    Points: 0
    Rank: Member

    Thank you good people.


    Get-CompInfo -ComputerName MyPC | % DiskInfo

    That's what I saw in some video! I remembered now once I saw your "foreach{$_.DiskInfo}".

    thank you

The topic ‘Select-Object -expandproperty SomeArray’ is closed to new replies.