Supports all PS versions
Get-ChildItem does not support advanced filtering of files. It can only use simple wildcards, but not regular expressions.
Revolving around this problem, we can use the -match command to filter.
The following example will obtain all files in the windows directory that contain at least two consecutive numbers and the file name length does not exceed 8 characters:
Get-ChildItem -Path $env:windir -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.BaseName -match '\d{2}' -and $_.Name.Length -le 8 }
Pay attention to the file The attribute "BaseName" does not include the extension, so numbers appearing in the extension will not be counted.
For more Powershell-using regular expressions to find files related articles, please pay attention to the PHP Chinese website!