Is there a way to escape a complete string i powershell the same way the @"string" Works in C# I am writing a script and in there I have several strings that looks like this: D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
escaping one by one There's is a long way home
This means that if you hard code a Distinguished Name in PowerShell, and the string is enclosed in double quotes, any embedded double quotes must be escaped first by a backtick "`", and then by a backslash "\".
PowerShell Regular Expressions Escape special characters To use these characters, as a . , + etc., in a pattern, you need to escape them to remove their special meaning. This is done by using the escape character which is a backslash \ in regex. Example: To search for + , you would use the pattern \+ .
To quote verbatim strings in Powershell, just use single quotes:
'D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)'
see
Get-Help about_Quoting_Rules
or Here
You don't need a verbatim string modifier in PowerShell since backslashes are literals (and quotes are escaped by doubling).
For a multiline string, use
$x = @"
"
Curiouser
and
curiouser
!
"
"@
The keyword I was missing was verbatim:
http://www.johndcook.com/blog/2008/01/22/c-verbatim-strings-vs-powershell-here-strings/
https://technet.microsoft.com/en-us/library/ee692792.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With