Deadly-Bagel almost had it I think. Don't use double quotes in $outputpath to keep Get-Content happy, but add them in your argument list string.
Be sure to escape with backtick `. In fact you might just want to do that with all the paths:
$outputpath = 'C:\Users\bob\Desktop\output new.xml'
Start -FilePath $sqlpackage -ArgumentList "/action:DeployReport /SourceFile:`"$dacpacpath`" /Profile:`"$profilepath`" /OutputPath:`"$outputpath`"" -NoNewWindow -Wait
[xml]$xmldocument = Get-Content -Path $outputpath
Answer from Josh Petitt on Stack OverflowDeadly-Bagel almost had it I think. Don't use double quotes in $outputpath to keep Get-Content happy, but add them in your argument list string.
Be sure to escape with backtick `. In fact you might just want to do that with all the paths:
$outputpath = 'C:\Users\bob\Desktop\output new.xml'
Start -FilePath $sqlpackage -ArgumentList "/action:DeployReport /SourceFile:`"$dacpacpath`" /Profile:`"$profilepath`" /OutputPath:`"$outputpath`"" -NoNewWindow -Wait
[xml]$xmldocument = Get-Content -Path $outputpath
-ArgumentList accepts String[] so try the following:
$outputpath = "C:\Users\bob\Desktop\output new.xml"
Start -FilePath $sqlpackage -ArgumentList @("/action:DeployReport", "/SourceFile:$dacpacpath", "/Profile:$profilepath", "/OutputPath:$outputpath") -NoNewWindow -Wait
I suspect passing it all as one parameter causes it to be confused.
i am trying to execute a command in powershell wherein it contains spaces in the file path. After looking around, i found out that i need to escape the spaces using ` symbol and use single quotes to handle spaces properly. The issue is that my command contains variables as well so i need to use double quotes to get them to expand while getting executed. is there any way out ? Including example below wherein it only considers the path until the space character
Start-Process -FilePath "cmd.exe" -ArgumentList "/c C:\Users\$env:username\Downloads\Installer\_Silent` Install.cmd" -NoNewWindow -Wait
'C:\Users\Admin\Downloads\Installer\_Silent' is not recognized as an internal or external command, operable program or batch file.
How to deal with space in the path
windows - How to escape spaces in a PowerShell one-liner - Stack Overflow
Terminal doesn't handle PowerShell's space escape character correctly
escaping - How can I escape space in PowerShell? - Stack Overflow
$msbuild = "${env:ProgramFiles(x86)}" + '\MSBuild\14.0\Bin\MSBuild.exe'
Try this way. No spaces, so path should be fine.
Perhaps try using the the Call operator (&) instead of invoke-expression? I'm not sure how any output will be processed though.
$solution = "test.sln"
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
Exec { & $msbuild $solution /t:clean}
Exec { & $msbuild $solution }
Would this do what you want?:
& "C:\Windows Services\MyService.exe"
Use &, the call operator, to invoke commands whose names or paths are stored in quoted strings and/or are referenced via variables, as in the accepted answer. Invoke-Expression is not only the wrong tool to use in this particular case, it should generally be avoided.
You can escape the space by using single quotations and a backtick before the space:
$path = 'C:\Windows Services\MyService.exe'
$path -replace ' ', '` '
invoke-expression $path