I have this in an if statement and today it errors and it never has before. I tried it on another prompt and same error.
What am missing, why is it reading the \h as a escape h? I have tried it with single and double quotes.
If you want to validate that $SecureKeyPath has the value 'C:\01servers\hdi' exactly I would use the -eq operator (not case sensitive) instead of -match
Yeah, I was thinking I could get away with an exact match if the match had single quotes. But remembering that it is a regex, reminds me that is silly. Thanks!
Yeah, PowerShell knows to interpret a string as literal, but to the regex classes, a string is a string; .NET doesn’t really have the distinction of literal / expandable strings except as syntactic sugar, it’s not a fundamental part of the underlying implementation as much as it is in parts of PowerShell’s code.
As mentioned above, the [regex]::Escape() method is a very handy shortcut to have for when you want a literal match.