如何从PowerShell运行sqlcmd.exe

时间:2014-01-08 13:12:57

标签: powershell sqlcmd

我正在尝试这个并且它失败了

PS C:\Users\MooMin>$i = "MySQLInstanceName"
PS C:\Users\MooMin>& sqlcmd -S $i -E -q"SELECT @@VERSION"

我收到此错误:

Unrecognized token in source text.
At line:1 char:31
+ & sqlcmd -S "$i" -E -q"SELECT  <<<< @@VERSION"
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnrecognizedToken

我做错了什么?

1 个答案:

答案 0 :(得分:1)

-q和tsql语句之间缺少空格。试试这样,

sqlcmd -S $i -E -q "SELECT @@VERSION"