Skip Navigation LinksHome > View Post
True or False in PowerShell

Yesterday's post on PowerShell used a regular expression to find some files.

The example avoided negation in the where clause by matching strings that didn't have a particular pattern, using this regex:

"^[^\d\d -]"

Which would read something like "Match strings that don't have two digits followed by a space and a dash, at their start".

It would have been easier to match strings that do have that pattern and flip the where clause, with a regex that looks like this:

"^\d\d -"

And have a where clause like so

dir | where { $_.Name -match $re -eq $false }

Notice how we have to use $true and $false tokens - it took me a while to work that out!

Tags: Powershell

Josh Post By Josh Twist
14:14
29 Jul 2007

» Next Post: System.Packaging for your own files
« Previous Post: More links on PowerShell

Comments:

Post a comment:

Name  

E-mail (never shared)

URL

Comments  

Captcha ImageRefresh Image
What's this?
Enter code above