Мне нужно вызвать bcp.exe
из скрипта PowerShell. Мой код:
$dataBase = 'MyDb'
$ProdEinheitTable = 'dbo.ProdEinheit'
$ProzessdatenTable = 'dbo.Prozessdaten_aktuell'
$sqlServerUserName = 'sa'
$sqlServerPassword = 'Password'
$server = 'MSSQLLocalDB'
$bcp = & 'C:\Program Files\Microsoft SQL Server\110\Tools\Binn\bcp.exe'
, и я вызываю утилиту bcp
следующим образом:
$bcp_args = "$bcp $dataBase.$ProdEinheitTable IN $datFileName -f $fmtFileName -U $sqlServerUserName -P sqlServerPassword -S $server -n"
Invoke-Expression $bcp_args
Это дает мне ошибку
usage: : The term 'usage:' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ usage: C:\Program Files\Microsoft SQL Server\110\Tools\Binn\bcp.exe { ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (usage::String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Если яудалить &
из строки, я получаю исключение
C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ C:\Program Files\Microsoft SQL Server\110\Tools\Binn\bcp.exe MyDb.dbo ...
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Как мне позвонить bcp
из PowerShell?