This article describes how to use regular expressions to search for files in PowerShell. the regular expressions in PowerShell are the same as those in other languages of Microsoft, which is very convenient to use. All PS versions supported
Get-ChildItem does not support advanced file filtering. It can only use simple wildcards, but cannot use regular expressions.
To solve this problem, we can use the-match command to filter.
In the following example, all files in the windows directory that contain at least two consecutive numbers are obtained, and the file name length cannot exceed 8 characters:
Get-ChildItem-Path $ env: windir-Recurse-ErrorAction SilentlyContinue | Where-Object {$ _. baseName-match '\ d {2}'-and $ _. name. length-le 8}
Note that the "BaseName" attribute of the file does not include the extension, so that the number appears in the extended name and will not be counted.
More Powershell-use regular expressions to search for files!