title: PowerShell Create script from script
body: <p>I am looking to Create a Powershell Script from within a Powershell Script.</p>
  <p>The issue i am having is i need to build and run a script from a remote Powershell terminal to multiple machines. The Script must be on the local machine. Unfortunately, I don't think the Invoke-Command, or the Enter-PSSession are available as the version of Powershell installed on the various machines may not be compatible with them. Or this would have made life much easier :(</p>
  <p>So coming from a UNIX/Linux background i was hoping to create a PowerShell script using plain text and then execute the Script locally. Unfortunaly as a newbee to the World of Powershell i was hoping for the powershell script to pass plain text and not to pass the executed output to the powershell script being created on the local machine.</p>
  <p>To test the waters here is a small script i have written and the output. VS the Desired output.</p>
  <p>Thanks in Advance!</p>
  <p>Script:</p>
  <pre><code> $var = @&quot;
  ping 8.8.8.8 
  &quot;$env:computername&quot;
  &quot;@
  
  $var &gt; \Users\pc\Desktop\ping.ps1
  
  C:\Users\pc\Desktop\ping.ps1
  
  Remove-Item -Path C:\Users\pc\Desktop\ping.ps1 -Force 
  </code></pre>
  <p>Output</p>
  <pre><code>ping 8.8.8.8 
  &quot;DESKTOP-****&quot;
  </code></pre>
  <p>Desired Output</p>
  <pre><code>ping 8.8.8.8
  $env:computername
  </code></pre>