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!