相关疑难解决方法(0)

使用powershell脚本中的参数运行shell命令

我需要使用bcp从远程SQL数据库中提取并保存一些表.我想编写一个powershell脚本来为每个表调用bcp并保存数据.到目前为止,我有这个脚本为bcp创建必要的args.但是我无法弄清楚如何将args传递给bcp.每次我运行脚本时,它只会显示bcp帮助.这一定是非常容易的,我没有得到.

#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 =@{}
$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
Run Code Online (Sandbox Code Playgroud)

powershell bcp

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

bcp ×1

powershell ×1