简体   繁体   中英

Powershell execute file with path in parameters

I am trying to run SqlPackage.exe from Powershell using a variable string as SourceFile parameter:

$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

Where $OutputVariable is the folder containing the full path

Unfortunately I get the following error:

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

I tried surrounding with quotes and splitting the parameters but I did not get to a solution. Any idea?

Thanks in advance!

Apparently by trimming the $OutputVariable

$OutputVariable.Trim()

The problem is fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM