Finding Files Only or Folders Only

by Aug 30, 2012

In PowerShell v2, to list only files or only folders you had to do filtering yourself:

Get-ChildItem $env:windir | Where-Object { $_.PSIsContainer -eq $true }
Get-ChildItem $env:windir | Where-Object { $_.PSIsContainer -eq $false }

In PowerShell v3, Get-ChildItem is smart enough to do that for you:

Get-ChildItem $env:windir  -File
Get-ChildItem $env:windir -Directory

Twitter This Tip! ReTweet this Tip!