title: Running WinRM quickconfig for remote servers
body: <p>I am writing a PowerShell script that reads in a list of hosts from a file. I have tried two separate methods, having issues with both.</p>
  
  <p><strong>First Method</strong>:</p>
  
  <pre><code>$WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig }
  </code></pre>
  
  <p>This gives the following error message on some of the hosts:</p>
  
  <pre>
  WSManFault
      + CategoryInfo          : NotSpecified: (WSManFault:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
      + PSComputerName        : svclebetapool01.lehi.micron.com
  
      Message = Access is denied. 
  Error number:  -2147024891 0x80070005
  Access is denied. 
  </pre>
  
  <p><strong>Second Method</strong>:</p>
  
  <pre><code>$WinRM = C:\PSTools\PsExec.exe \\$server -s winrm.cmd quickconfig -q
  </code></pre>
  
  <p>This sets <code>$WinRM</code> to the exit code (1 on successful execution). If I redirect the output with <code>&gt;</code> or <code>&gt;&gt;</code>, then it displays the PsExec copyright. I am looking for the exact message that is created by the <code>WinRM quickconfig</code> command so that I know how to handle it in different situations.</p>