1

The following example script terminates at folder due to the space between name and number. How do I run the full string?

$path = "C:\folder1\folder 2"

Invoke-Expression "$path\DB_Migration\Migrate.exe --timeout=300 -a $path\Server\Application.Core.dll -db SqlServer -conn $connectionstring"

$path is actually $PSScriptRoot on a server where I cannot simply rename the folder.

Cheers

boxdog
  • 7,894
  • 2
  • 18
  • 27
Jinx
  • 33
  • 5
  • Have you tried using single quotes e.g. `Invoke-Expression "'$path\DB_Migration\Migrate.exe' --timeout=300..."` – gvee Nov 07 '18 at 10:46
  • Wouldn't the single quote prevent the variable substitution? – Jinx Nov 07 '18 at 10:54
  • 2
    @Jinx - If you have double-quotes on the 'outside' and single-quotes on the 'inside', substitution still works. Give it a try: `$world = 'world'; "'Hello $world'"` – boxdog Nov 07 '18 at 10:57
  • Tested and you are correct that the single quotes do allow the variable to be parsed (which is good to know - thanks) however they then prevent the parameters being accepted – Jinx Nov 07 '18 at 11:21
  • 1
    why not just use `start-process` instead of `invoke-expression`? then you wouldnt have to cramp everything into a single string – Paul Nov 07 '18 at 11:50

1 Answers1

0

First, using Invoke-Expression should be avoid

Avoid using Invoke-Expression (Microsoft.com)

Suggestion: Use & operator.

Read: How to run an EXE file in PowerShell with parameters with spaces and quotes

seongjoo
  • 471
  • 5
  • 16