how to include a “:” as a parameter in powershell?

浪尽此生 提交于 2019-12-11 10:56:20

问题


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


回答1:


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"




回答2:


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"}




回答3:


The backquote character is the escape code in PowerShell. So write ``:` ....

oops... That won't work for the colon character. Use %3A instead.



来源:https://stackoverflow.com/questions/3130376/how-to-include-a-as-a-parameter-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!