I’d like to find get a list of files within a certain directory but I need to include two different extension types (particularly *.cer and *.crt).
Does the Get-ChildItem -Filter accept regular expressions?
If not how else can I do what I need to do?
you can use,
| select-string -pattern “your regex”
The filter parameter only qualifies the Path parameter so it wouldn’t help you filter by file name. You can try piping to where-object
Get-ChildItem … | Where-Object { {$_.Name -match “regex”}
Thank you. Here’s what I came up with.
$CertificateFileRegEx = ‘.cer|.crt’
$Certifcates = Get-ChildItem -Path $CertificatePath | Where-Object -FilterScript {$_.Name -match $CertificateFileRegEx}
All the variables are unneccesary.
gci | ? -FilterScript {$_.name -match “csv|bin”}
Simplified syntax kills puppies;-)
Thanks Dan. I’m putting together an advanced function which is why I’m being so verbose and using variables.