title: Importing Scriptblock from file
body: <p>I've got a working Powershell script and I'd like to have the scriptblock pulled in from an external file. </p>
  
  <p><strong>Working:</strong></p>
  
  <pre><code>$scriptblock = { ... }
  invoke-command -ComputerName $server -ScriptBlock $Scriptblock -ArgumentList $server,$team -Credential $credential -asjob -JobName Dashboard_$server -SessionOption (New-PSSessionOption -NoMachineProfile)
  </code></pre>
  
  <p>Output of "get-job -id  | receive-job" is fine</p>
  
  <p><strong>Not working:</strong></p>
  
  <pre><code># Generate scriptblock from file
  $file = Get-Content E:\Dashboard\Windows\winrm_scriptblock.txt
  $Scriptblock = $executioncontext.invokecommand.NewScriptBlock($file)
  
  invoke-command -ComputerName $server -ScriptBlock $Scriptblock -ArgumentList $server,$team -Credential $credential -asjob -JobName Dashboard_$server -SessionOption (New-PSSessionOption -NoMachineProfile)
  </code></pre>
  
  <p>Output of "get-job -id  | receive-job" is empty</p>
  
  <p>The contents of winrm_scriptblock.txt is exactly what is included between the braces in the scriptblock variable defined in the working version.</p>
  
  <p>Any assistance is appreciated.   </p>