如何包含“:”作为 powershell 中的参数?
我有一个简单的 powershell 脚本,就像这样,
sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a"
但我总是收到错误消息,
Sqlcmd: ':a': Invalid argument. Enter '-?' for help.
我发现是参数中的 ":"
导致了问题,但我不知道如何逃避它。
谢谢, 大卫
i have a simple powershell script, like this
sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a"
but i always got the error message
Sqlcmd: ':a': Invalid argument. Enter '-?' for help.
i figured out that it is the ":"
in the argument caused the problem, but i do not know how to escape it.
thanks,
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉,我必须再次回答我自己的问题。
解决这个问题的唯一方法是使用“+”连接两个字符串,而“:”将被保留。
例如 $a="abc"+":123"
sorry that i have to answer to my own question again.
the only way to solve this problem is to use '+' to concatenate the two string, and the ':' will be reserved.
e.g. $a="abc"+":123"
您也可以尝试我们用于编写 xdt:Transforms 脚本的方法。
$xmlSection.SetAttribute("xdtTransform","Insert")
后跟
foreach-object {$_ -replace "xdtTransform" , "xdt:Transform"}
You could also alternatively try this approach that we used for scripting xdt:Transforms.
$xmlSection.SetAttribute("xdtTransform","Insert")
followed by
foreach-object {$_ -replace "xdtTransform" , "xdt:Transform"}
反引号字符是 PowerShell 中的转义码。所以写 ``:` ....哎呀...这对冒号字符不起作用。请改用
%3A
。The backquote character is the escape code in PowerShell. So write ``:` ....oops... That won't work for the colon character. Use
%3A
instead.