Skip to content

Instantly share code, notes, and snippets.

@benjamine
Created January 12, 2014 05:34
Show Gist options
  • Save benjamine/8381365 to your computer and use it in GitHub Desktop.
Save benjamine/8381365 to your computer and use it in GitHub Desktop.
simplistic WinRM CLI ruby script for Vagrant Windows guest machines ( https://github.com/WinRb/vagrant-windows )
#!/usr/bin/env ruby
# requires:
# gem instal -r winrm
# gem install active_support
command = ARGV.join(' ')
if not command
raise "no command specified, usage: winrm <windows command>"
end
require 'active_support/core_ext/kernel/reporting'
# Silencing warnings because not all versions of GSSAPI support all of the GSSAPI methods
# the gssapi gem attempts to attach to and these warnings are dumped to STDERR.
silence_warnings do
# Requiring winrm before all other gems because of https://github.com/WinRb/WinRM/issues/39
require 'winrm'
end
endpoint = 'http://localhost:5985/wsman'
usr = 'vagrant'
pwd = 'vagrant'
winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => usr, :pass => pwd, :basic_auth_only => true, :disable_sspi => true)
winrm.cmd(command) do |stdout, stderr|
STDOUT.print stdout
STDERR.print stderr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment