PowerShell: Finding Files Only or Folders Only

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

Leave a Reply

Your email address will not be published.