PowerShell tips for using Get-childitem to get the specified file name extension _powershell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.