How to include ":" as a parameter in powershell?

i has a simple powershell script like this

sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a"

      

but i always got the error

Sqlcmd: ':a': Invalid argument. Enter '-?' for help.

      

I realized that this argument ":"

in argument was causing the problem, but I don't know how to avoid it.

thanks david

+1


source to share


3 answers


Sorry that I have to answer my own question again.

the only way to solve this problem is to use "+" to concatenate two strings, and ":" will be reserved.



eg. $ A = "ABC" + ": 123"

+3


source


You can also try this approach that we used for xdt: Transforms scripts.

$xmlSection.SetAttribute("xdtTransform","Insert")



followed by

foreach-object {$_ -replace "xdtTransform" , "xdt:Transform"}

0


source


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

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

.

-1


source







All Articles