如何包含“:”作为 powershell 中的参数?

发布于 2024-09-07 10:19:19 字数 272 浏览 4 评论 0原文

我有一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

送舟行 2024-09-14 10:19:19

抱歉,我必须再次回答我自己的问题。

解决这个问题的唯一方法是使用“+”连接两个字符串,而“:”将被保留。

例如 $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"

_失温 2024-09-14 10:19:19

您也可以尝试我们用于编写 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"}

烟若柳尘 2024-09-14 10:19:19

反引号字符是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文