1

is there any comlet like expand-string?

$a="ab cd"
$command = 'dir $a'
Write-Host (expand-string $command)

expected:

dir abcd

Note, I know I can just use $command="dir $a" to expand the string, but that was not I want to, I need to save the string dir $a as a literal in a variable and expand it later in a command.

3
  • what are you trying to achieve? not "expand a doublly-embedded string" ... WHY are you wanting to do that? there may be other ways to do it ... [grin] ///// have you looked into using a scriptblock instead of a string? if that doesn't work for you, perhaps Invoke-Command would work - it RUNS the string instead of simply expanding it. Commented Jul 13, 2019 at 20:20
  • 2
    $ExecutionContext.InvokeCommand.ExpandString($Command) Commented Jul 13, 2019 at 20:30
  • See stackoverflow.com/q/53797850/45375 Commented Feb 2, 2020 at 23:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.