我有以下c#代码:
var powerShell = PowerShell.Create();
powerShell.Runspace = runspace;
powerShell.AddArgument(connectionString);
powerShell.AddArgument(storedProc);
powerShell.AddArgument(dataSource);
powerShell.AddArgument(filterList);
powerShell.AddArgument(destinationFile);
var script = "path\to\the\powershell.ps1";
powerShell.AddScript(script);
powerShell.Invoke();我希望它能与powershell脚本一起工作:
$connString = $args[0]
$spName = $args[1]
$dataSource = $args[2]
$filterList = $args[3]
$destinationFile = $args[4]
bcp "$spName $filterList" queryout "$destinationFile" -c -t"\0" $connString我没有使用powershell的经验。你们这些家伙和女士们觉得这样对吗?那.NET代码呢?这会像我假设的那样运行脚本吗?
发布于 2014-06-11 12:43:11
您的C#需要进行一些调整。首先,在添加命令之前,您不能添加参数。其次,AddScript()方法需要Powershell.ps1的脚本内容,而不是路径。试试这个:
var ps = PowerShell.Create();
ps.Runspace = runspace;
var script = System.IO.File.ReadAllText(@"path\to\the\powershell.ps1");
ps.AddScript(script)
ps.AddArgument(connectionString);
ps.AddArgument(storedProc);
ps.AddArgument(dataSource);
ps.AddArgument(filterList);
ps.AddArgument(destinationFile);
var results = ps.Invoke();https://stackoverflow.com/questions/24147409
复制相似问题