title: Enabling PowerShell Remoting with psexec as script
body: <p>If I run: </p>
  
  <pre><code>C:\psexec.exe \\$compname -s powershell Enable-PSRemoting -Force 
  </code></pre>
  
  <p>as a command it works fine, but as soon as I put it into a foreach loop I get an error message saying the handle is invalid. Any way to fix this?</p>
  
  <p>Here's my loop:</p>
  
  <pre><code>$computerlist = Get-Content C:\computernames\WorkstationList.txt
  
  foreach ($compname in $computerlist){
  
  C:\psexec.exe \\$compname -s powershell Enable-PSRemoting -Force 
  
  }
  </code></pre>