I like the idea of creating constants (read-only variables) for data that will not change in a script. However, I have not been able to figure out how to cast a constant. For instance, I want to declare a regex pattern at the beginning of a script that I may use in several places.
New-Variable -Name p -Value “regex(#\d+)” -Description “REGEX pattern for matching numbered processes” -Force -Option ReadOnly
This give the appearance of working. However, when I do a $p.gettype() it shows as a string. This is true whether I put the double-quote to the left or the right of the [regex] declaration.
I have no problems casting this string as a regex in a regular variable. I’d just like to be able to create a constant here.