title: Chef/Ruby: Bad HTTP response returned from server (401). (WinRM::WinRMHTTPTransportError)Ruby:
body: <p><strong>Note: I'm using Active Directory authentication - there's no way around this.</strong></p>
  
  <p>I'm trying to use the following script:</p>
  
  <pre><code>require 'winrm'
  
  IP=ARGV[0]
  USER=ARGV[1]
  endpoint = "http://#{IP}:5985/wsman"
  winrm = WinRM::WinRMWebService.new endpoint, :plaintext, user: USER, pass: 'secret', basic_auth_only: true
  winrm.set_timeout 1800
  
  installer_file = "c:\\Users\\#{USER}\\Downloads\\chef_client.msi"
  installer_cmd = "msiexec /qn /i #{installer_file} ADDLOCAL=\"ChefServiceFeature,ChefClientFeature\""
  
  puts 'Installating Chef'
  puts installer_cmd
  install_output = winrm.cmd installer_cmd
  
  sleep 300
  puts 'Configuring Chef'
  winrm.cmd %Q(mv c:\\Users\\#{USER}\\Downloads\\client.rb c:\\chef\\client.rb)
  winrm.cmd %Q(mv c:\\Users\\#{USER}\\Downloads\\chef-validator.pem c:\\chef\\validation.pem)
  winrm.cmd 'net start chef-client || net start chef-client'
  </code></pre>
  
  <p>When I do:  <code>ruby chef_windows_boostrap.rb test168.domain.com ctote</code>, I get the following output:</p>
  
  <pre><code>c:\opscode\chef&gt;ruby chef_windows_boostrap.rb test168.domain.com ctote
  Installating Chef
  msiexec /qn /i c:\Users\ctote\Downloads\chef_client.msi ADDLOCAL="ChefServiceFeature,ChefClientFeature"
  C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/winrm-1.1.3/lib/winrm/http/transport.rb:48:in `send_request': Bad HTTP response returned from server (401). (WinRM::WinRMHTTPTransportError)
          from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/winrm-1.1.3/lib/winrm/winrm_service.rb:368:in `send_message'
          from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/winrm-1.1.3/lib/winrm/winrm_service.rb:113:in `open_shell'
          from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/winrm-1.1.3/lib/winrm/winrm_service.rb:239:in `run_cmd'
          from chef_windows_boostrap.rb:14:in `&lt;main&gt;'
  </code></pre>
  
  <p>below is my winrm config settings:</p>
  
  <pre><code>c:\opscode\chef&gt;winrm get winrm/config
  Config
      MaxEnvelopeSizekb = 150
      MaxTimeoutms = 1800000
      MaxBatchItems = 32000
      MaxProviderRequests = 4294967295
      Client
          NetworkDelayms = 5000
          URLPrefix = wsman
          AllowUnencrypted = true
          Auth
              Basic = true
              Digest = true
              Kerberos = true
              Negotiate = true
              Certificate = true
              CredSSP = false
          DefaultPorts
              HTTP = 5985
              HTTPS = 5986
          TrustedHosts
      Service
          RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GWGX;;;WD)
          MaxConcurrentOperations = 4294967295
          MaxConcurrentOperationsPerUser = 15
          EnumerationTimeoutms = 60000
          MaxConnections = 25
          MaxPacketRetrievalTimeSeconds = 120
          AllowUnencrypted = true
          Auth
              Basic = true
              Kerberos = true
              Negotiate = true
              Certificate = false
              CredSSP = false
              CbtHardeningLevel = Relaxed
          DefaultPorts
              HTTP = 5985
              HTTPS = 5986
          IPv4Filter = *
          IPv6Filter = *
          EnableCompatibilityHttpListener = false
          EnableCompatibilityHttpsListener = false
          CertificateThumbprint
      Winrs
          AllowRemoteShellAccess = true [Source="GPO"]
          IdleTimeout = 180000
          MaxConcurrentUsers = 5
          MaxShellRunTime = 2147483647
          MaxProcessesPerShell = 15
          MaxMemoryPerShellMB = 300
          MaxShellsPerUser = 5
  </code></pre>
  
  <p>At this point, I'm pretty lost on what to try - anyone have some suggestions? Is there a way I can wireshark this to help debug or something?</p>