class WinRM::Connection
WinRM
connection used to establish a session with the remote WinRM
service.
Attributes
Public Class Methods
Source
# File lib/winrm/connection.rb, line 26 def initialize(connection_opts) configure_connection_opts(connection_opts) configure_logger end
Creates a new WinRM
connection See the ConnectionOpts
class for connection options.
Public Instance Methods
Source
# File lib/winrm/connection.rb, line 56 def run_wql(wql, namespace = 'root/cimv2/*', &block) query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace) query.process_response(transport.send_request(query.build), &block) end
Executes a WQL query against the WinRM
connection @param wql [String] The wql query @param namespace [String] namespace for query - default is root/cimv2/* @return [Hash] Hash representation of wql query response (Hash is empty if a block is given) @yeild [type, item] Yields the time name and item for every item
Source
# File lib/winrm/connection.rb, line 38 def shell(shell_type, shell_opts = {}) shell = shell_factory.create_shell(shell_type, shell_opts) if block_given? begin yield shell ensure shell.close end else shell end end
Creates a new shell on the remote Windows server associated with this connection. @param shell_type [Symbol] The shell type :cmd or :powershell @param shell_opts [Hash] Options targeted for the created shell @return [Shell] PowerShell or Cmd shell instance.
Private Instance Methods
Source
# File lib/winrm/connection.rb, line 63 def configure_connection_opts(connection_opts) @connection_opts = ConnectionOpts.create_with_defaults(connection_opts) end
Source
# File lib/winrm/connection.rb, line 67 def configure_logger @logger = Logging.logger[self] logger.level = :warn logger.add_appenders(Logging.appenders.stdout) end
Source
# File lib/winrm/connection.rb, line 73 def shell_factory @shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger) end
Source
# File lib/winrm/connection.rb, line 77 def transport @transport ||= begin transport_factory = WinRM::HTTP::TransportFactory.new transport_factory.create_transport(@connection_opts) end end