Class: WinRM::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm/connection.rb

Overview

WinRM connection used to establish a session with the remote WinRM service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_opts) ⇒ Connection

Creates a new WinRM connection See the ConnectionOpts class for connection options.



28
29
30
31
# File 'lib/winrm/connection.rb', line 28

def initialize(connection_opts)
  configure_connection_opts(connection_opts)
  configure_logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



33
34
35
# File 'lib/winrm/connection.rb', line 33

def logger
  @logger
end

Instance Method Details

#run_wql(wql, namespace = 'root/cimv2/*', &block) ⇒ Hash

Executes a WQL query against the WinRM connection

Parameters:

  • wql (String)

    The wql query

  • namespace (String) (defaults to: 'root/cimv2/*')

    namespace for query - default is root/cimv2/*

Returns:

  • (Hash)

    Hash representation of wql query response (Hash is empty if a block is given)



58
59
60
61
# File 'lib/winrm/connection.rb', line 58

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

#shell(shell_type, shell_opts = {}) ⇒ Shell

Creates a new shell on the remote Windows server associated with this connection.

Parameters:

  • shell_type (Symbol)

    The shell type :cmd or :powershell

  • shell_opts (Hash) (defaults to: {})

    Options targeted for the created shell

Returns:

  • (Shell)

    PowerShell or Cmd shell instance.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/winrm/connection.rb', line 40

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