2

I've got 3 ps1 files under d:

-a---         6/19/2015   2:52 PM        104 Untitled1.ps1                                                                                                                       
-a---         6/19/2015   2:56 PM        204 Untitled2.ps1                                                                                                                       
-a---         6/16/2015   1:17 PM       3073 Untitled3.ps1  

I can use get-childitem to retrive them:

get-childitem d:\

But this fails:

 get-childitem d:\ -Force -Include *.ps1

This command doesn't show any thing. Why? I just want to filter out .ps1 file. Anything wrong with my command?

1 Answer 1

5

The Include parameter is effective only when the command includes the Recurse parameter or the path leads to the contents of a directory, such as C:\Windows*, where the wildcard character specifies the contents of the C:\Windows directory.

Source: https://technet.microsoft.com/en-us/library/hh849800.aspx

You can use the -Filter parameter instead:

Get-ChildItem -Path 'd:\' -Filter '*.ps1'

Or if you need to filter multiple extensions, use the wildcard character:

Get-ChildItem -Path 'd:\*' -Include '*.ps1', '*.bat'
Sign up to request clarification or add additional context in comments.

1 Comment

What if I wish to filter 2 types of file, "ps1", and "bat". How to write this command?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.