Comment exécuter sqlcmd à partir de powershell?

J'ai une chaîne de caractères dans powershell, qui contient un natif de commande sqlcmd. La commande peut être exécutée avec succès dans cmd.exe. J'ai de la difficulté à les mettre en powershell. Quelqu'un peut aider? Merci.

C'est sql.sql

select @@servername
go
select @@servicename

C'est le résultat quand j'execute la commande sqlcmd de cmd.exe

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>

C'est le script powershell pour appeler la commande sqlcmd.

$sql = @"
sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
"@

Invoke-Command $sql

Lorsque j'exécute ce script powershell, j'ai obtenu l'erreur suivante.

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
InformationsquelleAutor Ogrish Man | 2012-03-15