Author Posts

September 10, 2015 at 10:39 pm


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

September 11, 2015 at 1:39 am

(Get-CompInfo -ComputerName MyPC).DiskInfo

September 11, 2015 at 4:22 am

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.

September 11, 2015 at 5:01 am

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