title: Invoke-command fails until I run winrm quickconfig on remote server
body: <p>I'm trying to run a batch script on a remote server via powershell. Pretty straight forward:</p>
  
  <pre><code>$password = ConvertTo-SecureString "password" -AsPlainText -Force
  $cred= New-Object System.Management.Automation.PSCredential ("domain\user", $password)
  $sesh= new-pssession -computername "MSSCA" -credential $cred
  
  invoke-command -session $sesh -scriptblock {
      cmd.exe /C "C:\install.bat"
  }
  
  Remove-PSSession $sesh
  </code></pre>
  
  <p>This seems to randomly fail with the following error <img src="https://i.stack.imgur.com/7hhwi.png" alt="error"></p>
  
  <p><a href="https://i.stack.imgur.com/7hhwi.png" rel="nofollow noreferrer">Image link here</a></p>
  
  <p>On the remote machine, running the powershell command <code>winrm quickconfig</code> to configure the remote management service informs me that it's already set up to receive requests/remote management.</p>
  
  <p>Only AFTER running this command will <code>invoke-command</code> go through properly. How? I didn't even configure anything. How can I fix this?</p>