Powershell: get-childitem doesn't work for filters -


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 retrive them:

get-childitem d:\ 

but fails:

 get-childitem d:\ -force -include *.ps1 

this command doesn't show thing. why? want filter out .ps1 file. wrong command?

the include parameter effective only when command includes recurse parameter or path leads contents of directory, such c:\windows*, wildcard character specifies contents of c:\windows directory.

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

you can use -filter parameter instead:

get-childitem -path 'd:\' -filter '*.ps1' 

or if need filter multiple extensions, use wildcard character:

get-childitem -path 'd:\*' -include '*.ps1', '*.bat' 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

Mutual information between two matrices in R -