【发布时间】:2012-03-15 04:37:11
【问题描述】:
我在 powershell 中有一个字符串,其中包含一个本机 sqlcmd 命令。命令本身可以在cmd.exe中成功执行。我很难在 powershell 中执行它们。任何人都可以帮忙吗?谢谢。
这是 sql.sql
select @@servername
go
select @@servicename
这是我从 cmd.exe 执行 sqlcmd 命令时的结果
C:\Users\test>sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
--------------------------------------------------
thesimpsons\INSTANCE1
(1 rows affected)
--------------------------------------------------
INSTANCE1
(1 rows affected)
C:\Users\test>
这是调用 sqlcmd 命令的 powershell 脚本。
$sql = @"
sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
"@
Invoke-Command $sql
当我执行这个 powershell 脚本时,我得到了以下错误。
PS C:\TEMP> $sql = @"
sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
"@
Invoke-Command $sql
Invoke-Command : Parameter set cannot be resolved using the specified named parame
ters.
At line:5 char:15
+ Invoke-Command <<<< $sql
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBin
dingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands
.InvokeCommandCommand
【问题讨论】:
标签: powershell sqlcmd