Monthly Archive


File or Folder?

This is a common type of use for Get-ChildItem:

Get-ChildItem -Path c:\temp 

However, you could get files or folders returned.  Very often you just want to see the files

In PowerShell 1.0 & 2.0 you had to do this:

Get-ChildItem -Path c:\temp   | where {-not $_.PSIsContainer}

If you want to see the subfolders only then you reverse the condition:

Get-ChildItem -Path c:\temp  | where {$_.PSIsContainer}

In PowerShell 3.0 Get-ChildItem got some new parameters –File and –Directory. They display files only or folders only respectively. The default action is still to display files and folders.

Get-ChildItem -Path c:\temp  -File
Get-ChildItem -Path c:\temp  -Directory

I still see a lot of people making more work for themselves because they don’t use or don’t know about the new parameters.

Leave a Reply