Author Posts

September 16, 2015 at 5:12 am

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?

September 16, 2015 at 5:16 am

you can use,

| select-string -pattern "your regex"

September 16, 2015 at 5:29 am

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"}

September 16, 2015 at 6:39 am

Thank you. Here's what I came up with.

$CertificateFileRegEx = '.cer|.crt'
$Certifcates = Get-ChildItem -Path $CertificatePath | Where-Object -FilterScript {$_.Name -match $CertificateFileRegEx}

September 16, 2015 at 9:55 am

All the variables are unneccesary.

gci | ? -FilterScript {$ -match "csv|bin"}

Simplified syntax kills puppies;-)

September 16, 2015 at 10:27 am

Thanks Dan. I'm putting together an advanced function which is why I'm being so verbose and using variables.