Return only files with Get-childitem in powershell 2

Zakaria Belghiti picture Zakaria Belghiti · May 27, 2016 · Viewed 13.4k times · Source

I know that we can use the parameter -File in Powershell V3.0 but how can we get only files with the Get-childitem cmdlet in Powershell V2 ?

Answer

Martin Brandl picture Martin Brandl · May 27, 2016

You could use the Where-Object cmdlet to check the PSIsContainer property:

Get-ChildItem  | Where-Object { !$_.PSIsContainer }