PowerShell的SQLCMD [英] Powershell SQLCMD

查看:428
本文介绍了PowerShell的SQLCMD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在经历与PowerShell和SQLCMD,当有在-v参数变量的PowerShell不会运行命令sapces问题。

We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command.

例如

sqlcmd ... -v VAR="Some space"

有没有人经历过这之前或不知道如何来解决这个问题?

Has anyone experienced this before or know how to fix the problem?

谢谢,

推荐答案

的语法上述作品为PS命令行,但无法在脚本中。

The syntax above works for the PS commandline but fails within a script.

我们挣扎了很久着如何使这项工作。我们的一个非常聪明的QA家伙终于想出了以下内容:

We struggled a long time with how to make this work. One of our very clever QA guys finally came up with the following:

$variableWithSpaces="one two three"
$mySqlCmd = "sqlcmd -E -S $dbServer -i $script  -v var=```"$variableWithSpaces```" "
Invoke-Expression $mySqlCmd

插入丑陋,但它的工作原理。

Plug ugly but it works.

这篇关于PowerShell的SQLCMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆