Created
February 10, 2019 20:17
-
-
Save tothi/addf01e516bb3a54f73bde45cfd7db74 to your computer and use it in GitHub Desktop.
interactive remote powershell (winrm) with client certificate auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# https://github.com/WinRb/WinRM | |
# | |
require 'winrm' | |
opts = { | |
endpoint: 'https://xxx.xxx.xxx.xxx:5986/wsman', | |
transport: :ssl, | |
client_cert: 'certs/MyClient.cer', | |
client_key: 'certs/MyClient.key', | |
no_ssl_peer_verification: true | |
} | |
conn = WinRM::Connection.new(opts) | |
conn.shell(:powershell) do |shell| | |
output = shell.run('$PSVersionTable') do |stdout, stderr| | |
STDOUT.print stdout | |
STDERR.print stderr | |
end | |
command = "" | |
until command == "exit\n" do | |
print "PS > " | |
command = gets | |
output = shell.run(command) do |stdout, stderr| | |
STDOUT.print stdout | |
STDERR.print stderr | |
end | |
end | |
puts "The script exited with exit code #{output.exitcode}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment