Sha256: 7e4c00e0b254d61cb1e9b8683c7cab86db386b53d20ced06b1ff50bc572a1e58

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

# encoding: UTF-8
#
# Copyright 2014 Shawn Neal <sneal@sneal.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module WinRM
  # Wraps a PowerShell script to make it easy to Base64 encode for transport
  class PowershellScript
    attr_reader :text

    # Creates a new PowershellScript object which can be used to encode
    # PS scripts for safe transport over WinRM.
    # @param [String] The PS script text content
    def initialize(script)
      @text = script
    end

    # Encodes the script so that it can be passed to the PowerShell
    # --EncodedCommand argument.
    # @return [String] The UTF-16LE base64 encoded script
    def encoded
      encoded_script = text.encode('UTF-16LE', 'UTF-8')
      Base64.strict_encode64(encoded_script)
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
winrm-1.6.0 lib/winrm/helpers/powershell_script.rb
winrm-1.5.0 lib/winrm/helpers/powershell_script.rb
winrm-1.4.0 lib/winrm/helpers/powershell_script.rb
winrm-1.3.5 lib/winrm/helpers/powershell_script.rb
winrm-1.3.5.dev lib/winrm/helpers/powershell_script.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/winrm-1.3.4/lib/winrm/helpers/powershell_script.rb
winrm-1.3.4 lib/winrm/helpers/powershell_script.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/winrm-1.3.3/lib/winrm/helpers/powershell_script.rb
winrm-1.3.3 lib/winrm/helpers/powershell_script.rb
winrm-1.3.2 lib/winrm/helpers/powershell_script.rb
winrm-1.3.1 lib/winrm/helpers/powershell_script.rb
winrm-1.3.0 lib/winrm/helpers/powershell_script.rb