Run remote commands on a Windows machine from Linux using winrm

Quick and dirty: Run commands on a Windows machine from Linux.

On the windows host

Enable winrm:

winrm quickconfig

Enable basic authentication and permit Unencrypted traffic:

winrm set winrm/config/client/auth @{Basic="true"}
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}

On the linux host

Install the winrm ruby gem (might need ruby-dev):

gem install -r winrm

Create a ruby script that implements winrm (winrm-chef-client.rb):

require 'winrm'
endpoint = 'http://192.168.33.11:5985/wsman'
myuser = 'Administrator'
mypass = 'Password'
winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => myuser, :pass => mypass, :basic_auth_only => true)
winrm.cmd('chef-client') do |stdout, stderr|
    STDOUT.print stdout
    STDERR.print stderr
end

And execute your script with ruby:

ruby winrm-chef-client.rb