Ho una stringa in powershell, che contiene un comando nativo sqlcmd. Il comando stesso può essere eseguito correttamente in cmd.exe. Ho difficoltà ad eseguirli in PowerShell. Chiunque può aiutare? Grazie.Come eseguire sqlcmd da powershell?
Questo è sql.sql
select @@servername
go
select @@servicename
Questo è il risultato quando eseguo il comando sqlcmd da 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>
Questo è lo script PowerShell per chiamare il comando sqlcmd.
$sql = @"
sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
"@
Invoke-Command $sql
Quando eseguo questo script PowerShell, ho ricevuto il seguente errore.
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
correlati: http://stackoverflow.com/questions/1015038/powershell-sqlcmd –