title: Pass function as a parameter
body: <p>I've written function 'A' that will call one of a number of other functions. To save re-writing function 'A', I'd like to pass the function to be called as a parameter of function 'A'. For example:</p>
  
  <pre><code>function A{
      Param($functionToCall)
      Write-Host "I'm calling : $functionToCall"
  }
  
  function B{
      Write-Host "Function B"
  }
  
  Function C{
      write-host "Function C"
  }
  
  A -functionToCall C
  </code></pre>
  
  <p>Returns: I'm calling: C</p>
  
  <p>I am expecting it to return: I'm calling: Function C.</p>
  
  <p>I've tried various things such as:</p>
  
  <pre><code>Param([scriptblock]$functionToCall)
  </code></pre>
  
  <p>Cannot convert System.String to ScriptBlock</p>
  
  <pre><code>A -functionToCall $function:C
  </code></pre>
  
  <p>Returns "Write-Host "Function C"</p>
  
  <pre><code>A - functionToCall (&amp;C)
  </code></pre>
  
  <p>This evaluates before the rest of it:</p>
  
  <pre><code> Function C
   I'm Calling :
  </code></pre>
  
  <p>I'm sure this is programming 101, but I can't work out the correct syntax or what it is I'm doing wrong.</p>