Skip to content

Instantly share code, notes, and snippets.

@taylor
Forked from hh/mywinrm.rb
Created April 24, 2012 04:10
Show Gist options
  • Save taylor/2476340 to your computer and use it in GitHub Desktop.
Save taylor/2476340 to your computer and use it in GitHub Desktop.
run a command on a windows box via winrm
#!/usr/bin/env ruby
require 'rubygems'
require 'winrm'
HOST=ARGV[0]
PASSWORD=ARGV[1]
COMMAND=ARGV[2] # 'hostname'
begin
winrm = WinRM::WinRMWebService.new( "http://#{HOST}:5985/wsman",
:plaintext,
:user => "Administrator", :pass => PASSWORD,
:basic_auth_only => true)
winrm.cmd(COMMAND) do |stdout, stderr|
puts "#{HOST} -- #{stdout}" if stdout
puts "#{HOST} ERROR: #{stderr}" if stderr
end
rescue
puts "A low level error occured with #{HOST}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment