title: Can I resolve PowerShell scriptblock parameters without invoking?
body: <p>I'm looking at writing some PowerShell code that can either execute immediately, or produce the commands it would execute as generated scripts.</p>
  
  <p>I'd like to avoid this scenario:</p>
  
  <pre><code>if($Generating){
    write-Output "somecommand.exe"
  } 
  else{
    somecommand.exe  
  }
  </code></pre>
  
  <p>I got looking at ScriptBlocks, which at first looked promising because I can write the contents of the ScriptBlock to the console without executing it. Such as:</p>
  
  <pre><code>$sc = { somecommand.exe }
  $sc
   somecommand.exe
  </code></pre>
  
  <p>My specific question is, if my scriptblock contains parameters, can I get them to resolve when I'm writing the scriptblock contents to the console, but WITHOUT invoking the scriptblock?</p>
  
  <p>For example given the following scriptblock:</p>
  
  <pre><code>$b2 = { Param([string]$P) Write-Host "$P" }
  </code></pre>
  
  <p>When I just type "$b2" at the console and hit enter I see this:</p>
  
  <pre><code>Param([string]$P) Write-Host "$P"
  </code></pre>
  
  <p>What I'd like to see is this (if the parameter value is "Foo"):</p>
  
  <pre><code>Param([string]$P) Write-Host "Foo"
  </code></pre>
  
  <p>I realize this can be done when it's invoked, either via "&amp;" or using Invoke(), but would there be any way to get the parameters to resolve without invoking to make my script generation a little more elegant without needing a bunch of conditional statements throughout the code?</p>