[英]Unable to pass value from command line to Object - Powershell Paramter
I am trying to figure out how to pass a paramter that contains special characters in Powershell to an Object inside my function. 我试图弄清楚如何将Powershell中包含特殊字符的参数传递给函数内的对象。 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 现在我在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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.