title: PowerShell ScriptBlock and multiple functions
body: <p>I have written the following code:</p>
  
  <pre><code>cls
  function GetFoo() { 
      function GetBar() {
          $bar = "bar"
          $bar
      }
  
      $foo = "foo"
      $bar = GetBar
      $foo
      $bar
  }
  
  
  $cred = Get-Credential "firmwide\srabhi_adm"
  $result = Invoke-Command -Credential $cred -ComputerName localhost 
  -ScriptBlock ${function:GetFoo}
  Write-Host $result[0]
  Write-Host $result[1]
  </code></pre>
  
  <p>It works but I don't want to define <code>GetBar</code> inside of <code>GetFoo</code>.</p>
  
  <p>Can I do something like this?</p>
  
  <pre><code>cls
  function GetBar() {
      $bar = "bar"
      $bar
  }
  
  function GetFoo() {     
      $foo = "foo"
      $bar = GetBar
      $foo
      $bar
  }
  
  
  $cred = Get-Credential "firmwide\srabhi_adm"
  $result = Invoke-Command -Credential $cred -ComputerName localhost 
  -ScriptBlock ${function:GetFoo; function:GetBar; call GetFoo}
  Write-Host $result[0]
  Write-Host $result[1]
  </code></pre>
  
  <p>Basically I am selectively putting the functions which I want in the ScriptBlock and then calling one of them. This way I don't have to define function inside of function and I can construct the ScriptBlock by injecting the functions which I want to be a part of that ScriptBlock.</p>