Tengo una cadena en powershell, que contiene un comando nativo sqlcmd. El comando en sí mismo se puede ejecutar con éxito en cmd.exe. Tengo dificultades para ejecutarlos en PowerShell. Cualquiera puede ayudar? Gracias.¿Cómo ejecutar sqlcmd desde powershell?
Ésta es sql.sql
select @@servername
go
select @@servicename
Este es el resultado cuando ejecuto el comando 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>
Este es el script de PowerShell para llamar al comando sqlcmd.
$sql = @"
sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql"
"@
Invoke-Command $sql
Cuando ejecuto este script de powershell, recibo el siguiente error.
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
relacionados: http://stackoverflow.com/questions/1015038/powershell-sqlcmd –