Powershell在参数中执行带路径的文件

时间:2015-05-15 11:47:27

标签: powershell

我正在尝试使用变量字符串作为SourceFile参数从Powershell运行SqlPackage.exe:

$fileExe = "C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe"

& $fileExe /Action:Publish /SourceFile:$OutputVariable\file.dacpac /Profile:C:\sql\file.sqldatabase.publish.xml

其中$ OutputVariable是包含完整路径的文件夹

不幸的是我收到以下错误:

SqlPackage.exe : *** Illegal characters in path.
At C:\powershell\test.ps1:20 char:6
+      & $fileExe /Action:Publish /SourceFile:$OutputVariable\file.dacpac     /Profile:C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (*** Illegal characters in path.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

我尝试使用引号并拆分参数,但我没有找到解决方案。 有什么想法吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

显然是通过修剪$ OutputVariable

// School service created by DI framework
var class = schoolService.GetClassById(1);

// Student service created by DI framework
var student = studentService.GetStudentById(1);
var studentClasses = studentService.GetStudentClasses(student, class);

问题已解决。