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
powershell escaping invoke
add a comment |
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
powershell escaping invoke
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 usestart-process
instead ofinvoke-expression
? then you wouldnt have to cramp everything into a single string
– Paul
Nov 7 at 11:50
add a comment |
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
powershell escaping invoke
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
powershell escaping invoke
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 usestart-process
instead ofinvoke-expression
? then you wouldnt have to cramp everything into a single string
– Paul
Nov 7 at 11:50
add a comment |
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 usestart-process
instead ofinvoke-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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofinvoke-expression
? then you wouldnt have to cramp everything into a single string– Paul
Nov 7 at 11:50