I have script D, C and B :
ScriptD.ps1 ← caller
ScriptC.ps1 ← script path without space
Script B.ps1 ← script path with space
Script B & ScriptC:
Param([int]$Major, [int]$Minor, [String[]]$Output = @())
Write-Host "`n_______________________________________________________________________________________`n"
Write-Host "Script C:`nMajor = $Major ($($Major.GetType()))`nMinor = $Minor ($($Minor.GetType()))`nOutput = $Output (Type: $($Output.GetType()), Length: $($Output.Length))" -ForegroundColor Green
foreach($string in $Output) {
Write-Host "`t- $string"
}
Then I call ScriptC.ps1, Script B.ps1 from ScriptD.ps1:
$cmd1 = "C:\ScriptTest\ScriptC.ps1 -Major 1 -Minor 2 -Output A,B"
powershell -Command $cmd1 #WORK
$cmd2 = "C:\ScriptTest\Script B.ps1 -Major 1 -Minor 2 -Output A,B"
powershell -Command $cmd2 #DON'T WORK
$cmd2 = "'C:\ScriptTest\Script B.ps1' -Major 1 -Minor 2 -Output A,B" #DON'T WORK
$cmd2 = '"C:\ScriptTest\Script B.ps1" -Major 1 -Minor 2 -Output A,B' #DON'T WORK
$cmd2 = $('"{0}"' -f ("C:\ScriptTest\Script B.ps1")) + " -Major 1 -Minor 2 -Output A,B" #DON'T WORK
If there are spaces in the script path or in a variable the call don't work. Adding single quotes will not solve that problem.
What's wrong?
How could I use the -Command parameter with spaces in path and passed variables?
Get-Helpto readabout_operatorsesp, the& call operator,Invoke-Commandand-ArgumentList. Alsoabout_quoting