This gem allows you to break out of the magical WinRM constraints thus allowing to reach out to network shares and even install Windows updates, .NET, SQL Server etc.
require 'winrm'
require 'winrm-elevated'
conn = WinRM::Connection.new(...
conn.shell(:elevated) do |shell|
shell.run('$PSVersionTable') do |stdout, stderr|
STDOUT.print stdout
STDERR.print stderr
end
end
By passing a nil
password, winrm-elevated will assume that the command should run as a service account:
require 'winrm'
require 'winrm-elevated'
conn = WinRM::Connection.new(...
conn.shell(:elevated) do |shell|
shell.username = 'System'
shell.password = nil
shell.run('$PSVersionTable') do |stdout, stderr|
STDOUT.print stdout
STDERR.print stderr
end
end
By setting interactive_logon
to true
, the scheduled task will be configured to use an interactive logon allowing all command activity to be viewable from a RDP session if logged on as the same user as the winrm credentials:
require 'winrm'
require 'winrm-elevated'
conn = WinRM::Connection.new(...
conn.shell(:elevated) do |shell|
shell.interactive_logon = true
shell.run('notepad.exe')
end
The gem works by creating a new logon session local to the Windows box by using a scheduled task. After this point WinRM is just used to read output from the scheduled task via a log file.
If you're having trouble, first of all its most likely a network or WinRM configuration issue. Take a look at the WinRM gem troubleshooting first.
We use Bundler to manage dependencies during development.
$ bundle install
Once you have the dependencies, you can run the unit tests with rake
:
$ bundle exec rake spec
To run the integration tests you will need a Windows box with the WinRM service properly configured. Its easiest to use the Vagrant Windows box in the Vagrantilfe of this repo.
bundle exec rake integration