Return only files with Get-childitem in powershell 2

14,690

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

Get-ChildItem  | Where-Object { !$_.PSIsContainer }
Share:
14,690
Zakaria Belghiti
Author by

Zakaria Belghiti

Hello friends, I am a computer engineering student at ENSAT, web developer, passionate about new technologies, and an ambitious guy aspiring to enrich the world.

Updated on June 13, 2022

Comments

  • Zakaria Belghiti
    Zakaria Belghiti almost 2 years

    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 ?

  • Zakaria Belghiti
    Zakaria Belghiti almost 8 years
    Okay I'll try it, but does it work for not named files too?
  • Martin Brandl
    Martin Brandl almost 8 years
    what do you mean with not named files?
  • Zakaria Belghiti
    Zakaria Belghiti almost 8 years
    I mean files without extension
  • Martin Brandl
    Martin Brandl almost 8 years
    Yes, it will also include files without extensions.
  • Matt
    Matt almost 8 years
    Pretty sure you need to use brackets in v2.
  • Martin Brandl
    Martin Brandl almost 8 years
    Oh, thanks Matt, I updated my answer.