Subscribe to Windows IT Pro
December 15, 2009 12:00 AM

Get-ChildItem's -Include Parameter

Windows IT Pro
InstantDoc ID #103095
Rating: (0)

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.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.