我需要使用bcp从远程SQL数据库中提取并保存一些表。我想编写一个PowerShell脚本来调用每个表的bcp并保存数据。到目前为止,我有这个脚本为bcp创建必要的参数。但是我无法弄清楚如何将参数传递给bcp。每次运行脚本时,它都会显示bcp帮助。这一定很容易,我没有得到。使用powershell脚本中的参数运行shell命令
#commands bcp database.dbo.tablename out c:\temp\users.txt -N -t, -U uname -P pwd -S <servername>
$bcp_path = "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\bcp.exe"
$serverinfo [email protected]{}
$serverinfo.add('table','database.dbo.tablename')
$serverinfo.add('uid','uname')
$serverinfo.add('pwd','pwd')
$serverinfo.add('server','servername')
$out_path= "c:\Temp\db\"
$args = "$($serverinfo['table']) out $($out_path)test.dat -N -t, -U $($serverinfo['uid']) -P $($serverinfo['pwd']) -S $($serverinfo['server'])"
#this is the part I can't figure out
& $bcp_path $args
请参阅我的[问题](http://stackoverflow.com/q/21524101/107537)。如果可以的话请帮忙。 – Vijay 2014-02-03 09:53:44
这是值得检查Vijay的问题,因为它有一个比其他人更好的答案,如果你在PS V3。 – 2014-02-11 13:03:56