Don’t do that #27: Use Foreach-Object instead of of ByPropertyName

By | October 5, 2015

Don’t do that: You want to display the content of some files.

Get-ChildItem | ForEach-Object -Process { Get-Content -Path $_.FullName }

You don’t need to use Foreach-Object in this case, it is an additional work.

Do that: It is better to use the benefits of the pipeline bound parameters:

Get-ChildItem | Get-Content

Results are the same:


The parameter -Path accept pipeline input ByPropertyName.



Leave a Reply

Your email address will not be published.