Class: WinRM::PowershellScript

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

Overview

Wraps a PowerShell script to make it easy to Base64 encode for transport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script) ⇒ PowershellScript

Creates a new PowershellScript object which can be used to encode PS scripts for safe transport over WinRM.

Parameters:

  • The (String)

    PS script text content



25
26
27
# File 'lib/winrm/helpers/powershell_script.rb', line 25

def initialize(script)
  @text = script
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



20
21
22
# File 'lib/winrm/helpers/powershell_script.rb', line 20

def text
  @text
end

Instance Method Details

#encodedString

Encodes the script so that it can be passed to the PowerShell –EncodedCommand argument.

Returns:

  • (String)

    The UTF-16LE base64 encoded script



32
33
34
35
# File 'lib/winrm/helpers/powershell_script.rb', line 32

def encoded
  encoded_script = text.encode('UTF-16LE', 'UTF-8')
  Base64.strict_encode64(encoded_script)
end