I wrote the following pipe of commands:
get-process | where {$_.Path -notmatch ${env:SystemRoot} -and $_.Path -notmatch ${env:ProgramFiles} -and $_.Path -notmatch ${env:ProgramFiles(x86)} | select path, name
I got error:
parsing "C:\Program Files" - Malformed \p{X} character escape.
At line:1 char:22
+ get-process | where {$_.Path -notmatch $env:SystemRoot -and $_.Path -notmatch $e ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
I understood what happened and I did several tests. I called Get-ChildItem
cmdlet with paths with and without escape char. All work correctly. I put into Where-Object
FilterScript parameter script block which had paths with and without "\" escape char. Where-Object
with paths containing escape char worked correctly but when I put paths without escape char in Where-Object - I always get the error.
This isn't problem of system environment variables. I defined variable ProgramFilesA with "C:\Program Files" and variable ProgramFilesB with "C:\Program Files". When I use $env:ProgramFilesA
in Where-Object
I get error, when I use $env:ProgramFilesB
all works fine.
How I should call standard $env:
variables containing path in Where-Object
cmdlet to run it without errors?