When you use Get-childitem to get a list of output files, you may find that using the-filter parameter is much more than you would expect.
Here is an example that not only returns the. ps1 extension file but also returns the. ps1xml extension file:
To limit the result set only after you set the extension, you can add a command to the filter to perfect the result:
Get-childitem-path C:\windows-Recurse-ErrorAction Silentlycontinue-filter *.ps1 |
This will only return the specified extension file.
Mixed use of Get-childitem parameters
You can use multiple parameters of the Get-childitem cmdlet in the same command. Make sure you understand wildcard matching before mixing parameters. For example, the following command will not return the full result:
ps> Get-childitem-path C:\windows\*.dll-recurse-exclude [A-y]*.dll
It returns only DLLs under C:\Windows\ that do not start with a-y. The reason is that what you give is specific only C:\Windows\ under *.dll, which is inconsistent with recursive parameters-recurse because-recurse will return all the DLLs that meet the requirements in the C:\Windows\ directory and the recursive directory.
The following is the correct code:
To specify a recursive search for a file that matches the name to a specific pattern, use the-include parameter.
ps> get-childitem-path C:\Windows-Include *.dll-recurse-exclude [A-y]*.dll