Reputation: 564
I am trying to figure out how to pass a paramter that contains special characters in Powershell to an Object inside my function. Here is an example of my code.
function a{
param(
[string]$string
)
#convert to URL encoding here
#Query API
#Return JSON values
}
Now I type this in Powershell
PS> a foo(foo; bar) foo/bar ver1.0
And it fires on an error for ";" and then ")" being part of the string
Here is the error:
At line:1 char:32
+ a foo(foo; bar) foo/bar ver1.0
+ ~
Missing closing ')' in expression.
At line:1 char:41
+ a foo(foo; bar) foo/bar ver1.0
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInExpression
Upvotes: 0
Views: 588
Reputation: 22821
You have two options the way I see it.
Use single quotes:
a 'foo(foo; bar) foo/bar ver1.0'
Or escape all the special characters:
a foo`(foo`;` bar`)` foo/bar` ver1.0
Upvotes: 2