Powershell escaping a blank space in a variable











up vote
0
down vote

favorite












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



$path = "C:folder1folder 2"

Invoke-Expression "$pathDB_MigrationMigrate.exe --timeout=300 -a $pathServerApplication.Core.dll -db SqlServer -conn $connectionstring"


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



Cheers










share|improve this question
























  • Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
    – gvee
    Nov 7 at 10:46












  • Wouldn't the single quote prevent the variable substitution?
    – Jinx
    Nov 7 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 7 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 7 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 7 at 11:50

















up vote
0
down vote

favorite












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



$path = "C:folder1folder 2"

Invoke-Expression "$pathDB_MigrationMigrate.exe --timeout=300 -a $pathServerApplication.Core.dll -db SqlServer -conn $connectionstring"


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



Cheers










share|improve this question
























  • Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
    – gvee
    Nov 7 at 10:46












  • Wouldn't the single quote prevent the variable substitution?
    – Jinx
    Nov 7 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 7 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 7 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 7 at 11:50















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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



$path = "C:folder1folder 2"

Invoke-Expression "$pathDB_MigrationMigrate.exe --timeout=300 -a $pathServerApplication.Core.dll -db SqlServer -conn $connectionstring"


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



Cheers










share|improve this question















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



$path = "C:folder1folder 2"

Invoke-Expression "$pathDB_MigrationMigrate.exe --timeout=300 -a $pathServerApplication.Core.dll -db SqlServer -conn $connectionstring"


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



Cheers







powershell escaping invoke






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 10:41









boxdog

2,9452213




2,9452213










asked Nov 7 at 10:37









Jinx

132




132












  • Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
    – gvee
    Nov 7 at 10:46












  • Wouldn't the single quote prevent the variable substitution?
    – Jinx
    Nov 7 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 7 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 7 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 7 at 11:50




















  • Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
    – gvee
    Nov 7 at 10:46












  • Wouldn't the single quote prevent the variable substitution?
    – Jinx
    Nov 7 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 7 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 7 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 7 at 11:50


















Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
– gvee
Nov 7 at 10:46






Have you tried using single quotes e.g. Invoke-Expression "'$pathDB_MigrationMigrate.exe' --timeout=300..."
– gvee
Nov 7 at 10:46














Wouldn't the single quote prevent the variable substitution?
– Jinx
Nov 7 at 10:54




Wouldn't the single quote prevent the variable substitution?
– Jinx
Nov 7 at 10:54




2




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 7 at 10:57






@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 7 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 7 at 11:21




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 7 at 11:21




1




1




why not just use start-process instead of invoke-expression? then you wouldnt have to cramp everything into a single string
– Paul
Nov 7 at 11:50






why not just use start-process instead of invoke-expression? then you wouldnt have to cramp everything into a single string
– Paul
Nov 7 at 11:50



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187758%2fpowershell-escaping-a-blank-space-in-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187758%2fpowershell-escaping-a-blank-space-in-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()