How to resove variables in a powershell script block The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experiencePass arguments to a scriptblock in powershellSetting Windows PowerShell path variableDetermine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptHow to output something in PowerShellPowerShell says “execution of scripts is disabled on this system.”How to pass an argument to a PowerShell script?How do you comment out code in PowerShell?Best way to write to the console in PowerShellHow do I concatenate strings and variables in PowerShell?
He got a vote 80% that of Emmanuel Macron’s
Relations between two reciprocal partial derivatives?
Sort list of array linked objects by keys and values
"... to apply for a visa" or "... and applied for a visa"?
Change bounding box of math glyphs in LuaTeX
The variadic template constructor of my class cannot modify my class members, why is that so?
Is every episode of "Where are my Pants?" identical?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Why is superheterodyning better than direct conversion?
Hopping to infinity along a string of digits
Working through the single responsibility principle (SRP) in Python when calls are expensive
How to pronounce 1ターン?
How to delete random line from file using Unix command?
Why is the object placed in the middle of the sentence here?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
What are these Gizmos at Izaña Atmospheric Research Center in Spain?
Why can't wing-mounted spoilers be used to steepen approaches?
Derivation tree not rendering
Empty set is subset of every set? If yes, why that...
Create an outline of font
Typeface like Times New Roman but with "tied" percent sign
Difference between "generating set" and free product?
Can withdrawing asylum be illegal?
How to resove variables in a powershell script block
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experiencePass arguments to a scriptblock in powershellSetting Windows PowerShell path variableDetermine installed PowerShell versionTerminating a script in PowerShellHow to run a PowerShell scriptHow to output something in PowerShellPowerShell says “execution of scripts is disabled on this system.”How to pass an argument to a PowerShell script?How do you comment out code in PowerShell?Best way to write to the console in PowerShellHow do I concatenate strings and variables in PowerShell?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Given I have:
$a = "world"
$b = write-host "hello $a"
How to I get the resolved text of the script block, which should be:
write-host "hello world"
UPDATE: additional clarifications
If you just print $b you get the variable and not the resolved value
write-host "hello $a"
If you execute the script block with & $b you get the printed value, not the contents of the script block:
hello world
This question is seeking a string containing the contents of the script block with the evaluated variables, which is:
write-host "hello world"
powershell
add a comment |
Given I have:
$a = "world"
$b = write-host "hello $a"
How to I get the resolved text of the script block, which should be:
write-host "hello world"
UPDATE: additional clarifications
If you just print $b you get the variable and not the resolved value
write-host "hello $a"
If you execute the script block with & $b you get the printed value, not the contents of the script block:
hello world
This question is seeking a string containing the contents of the script block with the evaluated variables, which is:
write-host "hello world"
powershell
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...Invoke-Command -ScriptBlock $boutput =hello world
– Lee_Dailey
Mar 8 at 14:43
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
@Lee_Dailey - as you can see from the answer, you can do that using$ExecutionContext.InvokeCommand.ExpandString($b)
– alastairtree
Mar 8 at 16:52
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00
add a comment |
Given I have:
$a = "world"
$b = write-host "hello $a"
How to I get the resolved text of the script block, which should be:
write-host "hello world"
UPDATE: additional clarifications
If you just print $b you get the variable and not the resolved value
write-host "hello $a"
If you execute the script block with & $b you get the printed value, not the contents of the script block:
hello world
This question is seeking a string containing the contents of the script block with the evaluated variables, which is:
write-host "hello world"
powershell
Given I have:
$a = "world"
$b = write-host "hello $a"
How to I get the resolved text of the script block, which should be:
write-host "hello world"
UPDATE: additional clarifications
If you just print $b you get the variable and not the resolved value
write-host "hello $a"
If you execute the script block with & $b you get the printed value, not the contents of the script block:
hello world
This question is seeking a string containing the contents of the script block with the evaluated variables, which is:
write-host "hello world"
powershell
powershell
edited Mar 8 at 14:55
alastairtree
asked Mar 8 at 12:48
alastairtreealastairtree
1,8571631
1,8571631
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...Invoke-Command -ScriptBlock $boutput =hello world
– Lee_Dailey
Mar 8 at 14:43
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
@Lee_Dailey - as you can see from the answer, you can do that using$ExecutionContext.InvokeCommand.ExpandString($b)
– alastairtree
Mar 8 at 16:52
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00
add a comment |
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...Invoke-Command -ScriptBlock $boutput =hello world
– Lee_Dailey
Mar 8 at 14:43
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
@Lee_Dailey - as you can see from the answer, you can do that using$ExecutionContext.InvokeCommand.ExpandString($b)
– alastairtree
Mar 8 at 16:52
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...
Invoke-Command -ScriptBlock $b output = hello world– Lee_Dailey
Mar 8 at 14:43
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...
Invoke-Command -ScriptBlock $b output = hello world– Lee_Dailey
Mar 8 at 14:43
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
@Lee_Dailey - as you can see from the answer, you can do that using
$ExecutionContext.InvokeCommand.ExpandString($b)– alastairtree
Mar 8 at 16:52
@Lee_Dailey - as you can see from the answer, you can do that using
$ExecutionContext.InvokeCommand.ExpandString($b)– alastairtree
Mar 8 at 16:52
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00
add a comment |
1 Answer
1
active
oldest
votes
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:
$ExecutionContext.InvokeCommand.ExpandString($b)
Calling .InvokeCommand.ExpandString($b) on the current execution context will use the variables in the current scope for substitution.
The following is one way to create a scripblock and retrieve its contents:
$a = "world"
$b = [ScriptBlock]::create("write-host hello $a")
$b
write-host hello world
You can use your scriptblock notation as well to accomplish the same thing, but you need to use the & call operator:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
A feature to using the method above is that if you change the value of $a at any time and then call the scriptblock again, the output will be updated like so:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
$a = "hi"
& $b
write-host hello hi
The GetNewClosure() method can be used to create a clone of the scriptblock above to take a theoretical snapshot of the scriptblock's current evaluation. It will be immune to the changing of the $a value later the code:
$b = "write-host hello $a".GetNewClosure()
& $b
write-host hello world
$a = "new world"
& $b
write-host hello world
The notation denotes a scriptblock object as you probably already know. That can be passed into Invoke-Command, which opens up other options. You can also create parameters inside of the scriptblock that can be passed in later. See about_Script_Blocks for more information.
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just printswrite-host "hello $a"and the question asks forwrite-host "hello world"
– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
Found a short answer. Just run this$executioncontext.invokecommand.expandstring($b).
– AdminOfThings
Mar 8 at 15:51
|
show 1 more comment
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',
autoActivateHeartbeat: false,
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
);
);
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%2f55063570%2fhow-to-resove-variables-in-a-powershell-script-block%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:
$ExecutionContext.InvokeCommand.ExpandString($b)
Calling .InvokeCommand.ExpandString($b) on the current execution context will use the variables in the current scope for substitution.
The following is one way to create a scripblock and retrieve its contents:
$a = "world"
$b = [ScriptBlock]::create("write-host hello $a")
$b
write-host hello world
You can use your scriptblock notation as well to accomplish the same thing, but you need to use the & call operator:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
A feature to using the method above is that if you change the value of $a at any time and then call the scriptblock again, the output will be updated like so:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
$a = "hi"
& $b
write-host hello hi
The GetNewClosure() method can be used to create a clone of the scriptblock above to take a theoretical snapshot of the scriptblock's current evaluation. It will be immune to the changing of the $a value later the code:
$b = "write-host hello $a".GetNewClosure()
& $b
write-host hello world
$a = "new world"
& $b
write-host hello world
The notation denotes a scriptblock object as you probably already know. That can be passed into Invoke-Command, which opens up other options. You can also create parameters inside of the scriptblock that can be passed in later. See about_Script_Blocks for more information.
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just printswrite-host "hello $a"and the question asks forwrite-host "hello world"
– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
Found a short answer. Just run this$executioncontext.invokecommand.expandstring($b).
– AdminOfThings
Mar 8 at 15:51
|
show 1 more comment
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:
$ExecutionContext.InvokeCommand.ExpandString($b)
Calling .InvokeCommand.ExpandString($b) on the current execution context will use the variables in the current scope for substitution.
The following is one way to create a scripblock and retrieve its contents:
$a = "world"
$b = [ScriptBlock]::create("write-host hello $a")
$b
write-host hello world
You can use your scriptblock notation as well to accomplish the same thing, but you need to use the & call operator:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
A feature to using the method above is that if you change the value of $a at any time and then call the scriptblock again, the output will be updated like so:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
$a = "hi"
& $b
write-host hello hi
The GetNewClosure() method can be used to create a clone of the scriptblock above to take a theoretical snapshot of the scriptblock's current evaluation. It will be immune to the changing of the $a value later the code:
$b = "write-host hello $a".GetNewClosure()
& $b
write-host hello world
$a = "new world"
& $b
write-host hello world
The notation denotes a scriptblock object as you probably already know. That can be passed into Invoke-Command, which opens up other options. You can also create parameters inside of the scriptblock that can be passed in later. See about_Script_Blocks for more information.
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just printswrite-host "hello $a"and the question asks forwrite-host "hello world"
– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
Found a short answer. Just run this$executioncontext.invokecommand.expandstring($b).
– AdminOfThings
Mar 8 at 15:51
|
show 1 more comment
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:
$ExecutionContext.InvokeCommand.ExpandString($b)
Calling .InvokeCommand.ExpandString($b) on the current execution context will use the variables in the current scope for substitution.
The following is one way to create a scripblock and retrieve its contents:
$a = "world"
$b = [ScriptBlock]::create("write-host hello $a")
$b
write-host hello world
You can use your scriptblock notation as well to accomplish the same thing, but you need to use the & call operator:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
A feature to using the method above is that if you change the value of $a at any time and then call the scriptblock again, the output will be updated like so:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
$a = "hi"
& $b
write-host hello hi
The GetNewClosure() method can be used to create a clone of the scriptblock above to take a theoretical snapshot of the scriptblock's current evaluation. It will be immune to the changing of the $a value later the code:
$b = "write-host hello $a".GetNewClosure()
& $b
write-host hello world
$a = "new world"
& $b
write-host hello world
The notation denotes a scriptblock object as you probably already know. That can be passed into Invoke-Command, which opens up other options. You can also create parameters inside of the scriptblock that can be passed in later. See about_Script_Blocks for more information.
As in the original question, if your entire scriptblock contents is not a string (but you want it to be) and you need variable substitution within the scriptblock, you can use the following:
$ExecutionContext.InvokeCommand.ExpandString($b)
Calling .InvokeCommand.ExpandString($b) on the current execution context will use the variables in the current scope for substitution.
The following is one way to create a scripblock and retrieve its contents:
$a = "world"
$b = [ScriptBlock]::create("write-host hello $a")
$b
write-host hello world
You can use your scriptblock notation as well to accomplish the same thing, but you need to use the & call operator:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
A feature to using the method above is that if you change the value of $a at any time and then call the scriptblock again, the output will be updated like so:
$a = "world"
$b = "write-host hello $a"
& $b
write-host hello world
$a = "hi"
& $b
write-host hello hi
The GetNewClosure() method can be used to create a clone of the scriptblock above to take a theoretical snapshot of the scriptblock's current evaluation. It will be immune to the changing of the $a value later the code:
$b = "write-host hello $a".GetNewClosure()
& $b
write-host hello world
$a = "new world"
& $b
write-host hello world
The notation denotes a scriptblock object as you probably already know. That can be passed into Invoke-Command, which opens up other options. You can also create parameters inside of the scriptblock that can be passed in later. See about_Script_Blocks for more information.
edited Mar 8 at 16:59
answered Mar 8 at 13:19
AdminOfThingsAdminOfThings
1,9671212
1,9671212
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just printswrite-host "hello $a"and the question asks forwrite-host "hello world"
– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
Found a short answer. Just run this$executioncontext.invokecommand.expandstring($b).
– AdminOfThings
Mar 8 at 15:51
|
show 1 more comment
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just printswrite-host "hello $a"and the question asks forwrite-host "hello world"
– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
Found a short answer. Just run this$executioncontext.invokecommand.expandstring($b).
– AdminOfThings
Mar 8 at 15:51
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
Sorry, yeah meant $a not $b, although I think the question still stands. Updated the question
– alastairtree
Mar 8 at 13:40
This is not correct and misses the crus of the question - printing $b just prints
write-host "hello $a" and the question asks for write-host "hello world"– alastairtree
Mar 8 at 14:51
This is not correct and misses the crus of the question - printing $b just prints
write-host "hello $a" and the question asks for write-host "hello world"– alastairtree
Mar 8 at 14:51
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
Did you read through the post and try the different scenarios? You have to have quotes around everything inside of the scriptblock to print the entire text, which is there in my examples.
– AdminOfThings
Mar 8 at 14:56
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
I understand but you have changed the question to replace the contents of the script block with a string. Instead the question assumes you already have a script block, and want to print its contents without executing it.
– alastairtree
Mar 8 at 15:01
4
4
Found a short answer. Just run this
$executioncontext.invokecommand.expandstring($b).– AdminOfThings
Mar 8 at 15:51
Found a short answer. Just run this
$executioncontext.invokecommand.expandstring($b).– AdminOfThings
Mar 8 at 15:51
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55063570%2fhow-to-resove-variables-in-a-powershell-script-block%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
Possible duplicate of Pass arguments to a scriptblock in powershell
– arco444
Mar 8 at 13:14
you have a scriptblock and you need to invoke/run the scriptblock. [grin] simply calling the $Var that holds the scriptblock will give the literal content, not run it. you can run it thus ...
Invoke-Command -ScriptBlock $boutput =hello world– Lee_Dailey
Mar 8 at 14:43
I dont believe this is a duplicate because i am not executing the script block - i want a string of its syntax with evaluated variables
– alastairtree
Mar 8 at 14:57
@Lee_Dailey - as you can see from the answer, you can do that using
$ExecutionContext.InvokeCommand.ExpandString($b)– alastairtree
Mar 8 at 16:52
@alastairtree - ha! i learned something new! [grin] i will delete this comment soon - and immediately delete my wrong comment to avoid confusing folks.
– Lee_Dailey
Mar 8 at 17:00