Skip navigation

Get-ChildItem's -Include Parameter

Get-ChildItem's -Include parameter serves as a selection pattern for the -Path parameter; only items in the specified path that match the -Include parameter's argument will be returned. However, you must specify a wildcard pattern or filename for the -Path parameter's argument for -Include to work. For example, the following command won't return any results even if you have a C:\Data directory that contains .txt files:

get-childitem c:\data -include *.txt 

The command doesn't return any results because there's no wildcard pattern for -Include to qualify—it's simply a directory name without a filename pattern. You would use this command instead:

get-childitem c:\data\* -include *.txt 

This behavior extends to the subdirectories of a directory if you use * with the -include parameter. For example, consider this command:

get-childitem c:\data\* -include * 

The * wildcard matches directories, too, so this command lists not only the files in C:\Data but also the contents of first-level directories under C:\Data. To list only the items in C:\Data, omit the -Include parameter or specify its argument as $NULL.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.