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.



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

def initialize(connection_opts)
  configure_connection_opts(connection_opts)
  configure_logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

#run_wql(wql) ⇒ Hash

Executes a WQL query against the WinRM connection

Parameters:

  • wql (String)

    The wql query

Returns:

  • (Hash)

    Hash representation of wql query response



54
55
56
57
# File 'lib/winrm/connection.rb', line 54

def run_wql(wql)
  query = WinRM::WSMV::WqlQuery.new(@connection_opts, wql)
  query.process_response(transport.send_request(query.build))
end

#shell(shell_type) ⇒ Shell

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

Parameters:

  • shell_type (Symbol)

    The shell type :cmd or :powershell

Returns:

  • (Shell)

    PowerShell or Cmd shell instance.



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

def shell(shell_type)
  shell = shell_factory.create_shell(shell_type)
  if block_given?
    begin
      yield shell
    ensure
      shell.close
    end
  else
    shell
  end
end