winrm 1.3.5 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rspec +3 -3
- data/.rubocop.yml +9 -9
- data/.travis.yml +4 -4
- data/Gemfile +9 -9
- data/LICENSE +202 -202
- data/README.md +148 -148
- data/Rakefile +28 -28
- data/VERSION +1 -1
- data/Vagrantfile +9 -9
- data/bin/rwinrm +97 -97
- data/changelog.md +49 -46
- data/lib/winrm.rb +41 -41
- data/lib/winrm/exceptions/exceptions.rb +57 -57
- data/lib/winrm/helpers/iso8601_duration.rb +58 -58
- data/lib/winrm/helpers/powershell_script.rb +37 -37
- data/lib/winrm/http/response_handler.rb +82 -82
- data/lib/winrm/http/transport.rb +294 -294
- data/lib/winrm/output.rb +43 -43
- data/lib/winrm/soap_provider.rb +40 -40
- data/lib/winrm/winrm_service.rb +490 -488
- data/preamble +17 -17
- data/spec/auth_timeout_spec.rb +16 -16
- data/spec/cmd_spec.rb +102 -102
- data/spec/config-example.yml +19 -19
- data/spec/exception_spec.rb +50 -50
- data/spec/issue_59_spec.rb +15 -15
- data/spec/matchers.rb +74 -74
- data/spec/output_spec.rb +110 -110
- data/spec/powershell_spec.rb +103 -103
- data/spec/response_handler_spec.rb +59 -59
- data/spec/spec_helper.rb +48 -48
- data/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/spec/winrm_options_spec.rb +76 -76
- data/spec/winrm_primitives_spec.rb +51 -51
- data/spec/wql_spec.rb +14 -14
- data/winrm.gemspec +41 -41
- metadata +2 -2
data/changelog.md
CHANGED
@@ -1,46 +1,49 @@
|
|
1
|
-
# WinRM Gem Changelog
|
2
|
-
|
3
|
-
# 1.3.
|
4
|
-
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
9
|
-
|
10
|
-
# 1.3.
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- Fixed
|
25
|
-
|
26
|
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
|
42
|
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
-
|
1
|
+
# WinRM Gem Changelog
|
2
|
+
|
3
|
+
# 1.3.6
|
4
|
+
- Remove BOM from response (Issue #159) added by Windows 2008R2
|
5
|
+
|
6
|
+
# 1.3.5
|
7
|
+
- Widen logging version constraints to include 2.0
|
8
|
+
- Use codepage 65001 (UTF-8)
|
9
|
+
|
10
|
+
# 1.3.4
|
11
|
+
- Relaxed version pins on dev dependencies
|
12
|
+
|
13
|
+
# 1.3.3
|
14
|
+
- Fixed issue 133, rwinrm allow hostnames with dashes
|
15
|
+
- Use duck typing for powershell script read
|
16
|
+
|
17
|
+
# 1.3.2
|
18
|
+
- Add spec.license attribute to gemspec
|
19
|
+
- Bump RSpec dependency 3.0 to 3.2
|
20
|
+
|
21
|
+
# 1.3.1
|
22
|
+
- Fixed issue 129, long running commands could cause a stackoverflow exception
|
23
|
+
- Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
|
24
|
+
- Fixed issue 124 rwinrm won't take '.' characters in username
|
25
|
+
|
26
|
+
# 1.3.0
|
27
|
+
- Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
|
28
|
+
- Refactored and added more unit and integration tests
|
29
|
+
- Added ability to write to stdin
|
30
|
+
- Added rwinrm binary to launch remote shell
|
31
|
+
- Added WINRM_LOG env var to set log level
|
32
|
+
- Retry Kerberos auth once if 401 response is received
|
33
|
+
- Remove Savon dependency and use newer versions of underlying dependencies
|
34
|
+
- Remove Nokogiri dependency and replace with native Ruby XML
|
35
|
+
- Fixed issue 85, ensure WQL response is not nil
|
36
|
+
- All WinRM library errors inherit from base class WinRMError
|
37
|
+
- Integrations tests should now pass on Windows Server 2008+
|
38
|
+
- Bump Ruby NTLM gem version dependency
|
39
|
+
- HTTP client receive timeout is now configurable via set_timeout
|
40
|
+
- Added backwards compatible Output class to make it easier to collect output
|
41
|
+
- Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
|
42
|
+
- Added Rubocop to build
|
43
|
+
- Fixed error when commands contain a newline character
|
44
|
+
|
45
|
+
# 1.2.0
|
46
|
+
- Allow user to disable SSL peer ceritifcate validation #44
|
47
|
+
- Allow commands with "'" chars on Ruby 2.x, fixes #69
|
48
|
+
- Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
|
49
|
+
- Commands with non-ASCII chars should work, #70
|
data/lib/winrm.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'date'
|
18
|
-
require 'logging'
|
19
|
-
|
20
|
-
# Main WinRM module entry point
|
21
|
-
module WinRM
|
22
|
-
# Enable logging if it is requested. We do this before
|
23
|
-
# anything else so that we can setup the output before
|
24
|
-
# any logging occurs.
|
25
|
-
if ENV['WINRM_LOG'] && ENV['WINRM_LOG'] != ''
|
26
|
-
begin
|
27
|
-
Logging.logger.root.level = ENV['WINRM_LOG']
|
28
|
-
Logging.logger.root.appenders = Logging.appenders.stderr
|
29
|
-
rescue ArgumentError
|
30
|
-
# This means that the logging level wasn't valid
|
31
|
-
$stderr.puts "Invalid WINRM_LOG level is set: #{ENV['WINRM_LOG']}"
|
32
|
-
$stderr.puts ''
|
33
|
-
$stderr.puts 'Please use one of the standard log levels: ' \
|
34
|
-
'debug, info, warn, or error'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
require 'winrm/output'
|
40
|
-
require 'winrm/helpers/iso8601_duration'
|
41
|
-
require 'winrm/soap_provider'
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'date'
|
18
|
+
require 'logging'
|
19
|
+
|
20
|
+
# Main WinRM module entry point
|
21
|
+
module WinRM
|
22
|
+
# Enable logging if it is requested. We do this before
|
23
|
+
# anything else so that we can setup the output before
|
24
|
+
# any logging occurs.
|
25
|
+
if ENV['WINRM_LOG'] && ENV['WINRM_LOG'] != ''
|
26
|
+
begin
|
27
|
+
Logging.logger.root.level = ENV['WINRM_LOG']
|
28
|
+
Logging.logger.root.appenders = Logging.appenders.stderr
|
29
|
+
rescue ArgumentError
|
30
|
+
# This means that the logging level wasn't valid
|
31
|
+
$stderr.puts "Invalid WINRM_LOG level is set: #{ENV['WINRM_LOG']}"
|
32
|
+
$stderr.puts ''
|
33
|
+
$stderr.puts 'Please use one of the standard log levels: ' \
|
34
|
+
'debug, info, warn, or error'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'winrm/output'
|
40
|
+
require 'winrm/helpers/iso8601_duration'
|
41
|
+
require 'winrm/soap_provider'
|
@@ -1,57 +1,57 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
module WinRM
|
18
|
-
# WinRM base class for errors
|
19
|
-
class WinRMError < StandardError; end
|
20
|
-
|
21
|
-
# Authorization Error
|
22
|
-
class WinRMAuthorizationError < WinRMError; end
|
23
|
-
|
24
|
-
# A Fault returned in the SOAP response. The XML node is a WSManFault
|
25
|
-
class WinRMWSManFault < WinRMError
|
26
|
-
attr_reader :fault_code
|
27
|
-
attr_reader :fault_description
|
28
|
-
|
29
|
-
def initialize(fault_description, fault_code)
|
30
|
-
@fault_description = fault_description
|
31
|
-
@fault_code = fault_code
|
32
|
-
super("[WSMAN ERROR CODE: #{fault_code}]: #{fault_description}")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# A Fault returned in the SOAP response. The XML node is a MSFT_WmiError
|
37
|
-
class WinRMWMIError < WinRMError
|
38
|
-
attr_reader :error_code
|
39
|
-
attr_reader :error
|
40
|
-
|
41
|
-
def initialize(error, error_code)
|
42
|
-
@error = error
|
43
|
-
@error_code = error_code
|
44
|
-
super("[WMI ERROR CODE: #{error_code}]: #{error}")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# non-200 response without a SOAP fault
|
49
|
-
class WinRMHTTPTransportError < WinRMError
|
50
|
-
attr_reader :status_code
|
51
|
-
|
52
|
-
def initialize(msg, status_code)
|
53
|
-
@status_code = status_code
|
54
|
-
super(msg + " (#{status_code}).")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
# WinRM base class for errors
|
19
|
+
class WinRMError < StandardError; end
|
20
|
+
|
21
|
+
# Authorization Error
|
22
|
+
class WinRMAuthorizationError < WinRMError; end
|
23
|
+
|
24
|
+
# A Fault returned in the SOAP response. The XML node is a WSManFault
|
25
|
+
class WinRMWSManFault < WinRMError
|
26
|
+
attr_reader :fault_code
|
27
|
+
attr_reader :fault_description
|
28
|
+
|
29
|
+
def initialize(fault_description, fault_code)
|
30
|
+
@fault_description = fault_description
|
31
|
+
@fault_code = fault_code
|
32
|
+
super("[WSMAN ERROR CODE: #{fault_code}]: #{fault_description}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# A Fault returned in the SOAP response. The XML node is a MSFT_WmiError
|
37
|
+
class WinRMWMIError < WinRMError
|
38
|
+
attr_reader :error_code
|
39
|
+
attr_reader :error
|
40
|
+
|
41
|
+
def initialize(error, error_code)
|
42
|
+
@error = error
|
43
|
+
@error_code = error_code
|
44
|
+
super("[WMI ERROR CODE: #{error_code}]: #{error}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# non-200 response without a SOAP fault
|
49
|
+
class WinRMHTTPTransportError < WinRMError
|
50
|
+
attr_reader :status_code
|
51
|
+
|
52
|
+
def initialize(msg, status_code)
|
53
|
+
@status_code = status_code
|
54
|
+
super(msg + " (#{status_code}).")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,58 +1,58 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# rubocop:disable Metrics/MethodLength
|
18
|
-
# rubocop:disable Metrics/AbcSize
|
19
|
-
|
20
|
-
# Format an ISO8601 Duration
|
21
|
-
module Iso8601Duration
|
22
|
-
# Convert the number of seconds to an ISO8601 duration format
|
23
|
-
# @see http://tools.ietf.org/html/rfc2445#section-4.3.6
|
24
|
-
# @param [Fixnum] seconds The amount of seconds for this duration
|
25
|
-
def self.sec_to_dur(seconds)
|
26
|
-
seconds = seconds.to_i
|
27
|
-
iso_str = 'P'
|
28
|
-
if seconds > 604_800 # more than a week
|
29
|
-
weeks = seconds / 604_800
|
30
|
-
seconds -= (604_800 * weeks)
|
31
|
-
iso_str << "#{weeks}W"
|
32
|
-
end
|
33
|
-
if seconds > 86_400 # more than a day
|
34
|
-
days = seconds / 86_400
|
35
|
-
seconds -= (86_400 * days)
|
36
|
-
iso_str << "#{days}D"
|
37
|
-
end
|
38
|
-
if seconds > 0
|
39
|
-
iso_str << 'T'
|
40
|
-
if seconds > 3600 # more than an hour
|
41
|
-
hours = seconds / 3600
|
42
|
-
seconds -= (3600 * hours)
|
43
|
-
iso_str << "#{hours}H"
|
44
|
-
end
|
45
|
-
if seconds > 60 # more than a minute
|
46
|
-
minutes = seconds / 60
|
47
|
-
seconds -= (60 * minutes)
|
48
|
-
iso_str << "#{minutes}M"
|
49
|
-
end
|
50
|
-
iso_str << "#{seconds}S"
|
51
|
-
end
|
52
|
-
|
53
|
-
iso_str
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# rubocop:enable Metrics/MethodLength
|
58
|
-
# rubocop:enable Metrics/AbcSize
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# rubocop:disable Metrics/MethodLength
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
|
20
|
+
# Format an ISO8601 Duration
|
21
|
+
module Iso8601Duration
|
22
|
+
# Convert the number of seconds to an ISO8601 duration format
|
23
|
+
# @see http://tools.ietf.org/html/rfc2445#section-4.3.6
|
24
|
+
# @param [Fixnum] seconds The amount of seconds for this duration
|
25
|
+
def self.sec_to_dur(seconds)
|
26
|
+
seconds = seconds.to_i
|
27
|
+
iso_str = 'P'
|
28
|
+
if seconds > 604_800 # more than a week
|
29
|
+
weeks = seconds / 604_800
|
30
|
+
seconds -= (604_800 * weeks)
|
31
|
+
iso_str << "#{weeks}W"
|
32
|
+
end
|
33
|
+
if seconds > 86_400 # more than a day
|
34
|
+
days = seconds / 86_400
|
35
|
+
seconds -= (86_400 * days)
|
36
|
+
iso_str << "#{days}D"
|
37
|
+
end
|
38
|
+
if seconds > 0
|
39
|
+
iso_str << 'T'
|
40
|
+
if seconds > 3600 # more than an hour
|
41
|
+
hours = seconds / 3600
|
42
|
+
seconds -= (3600 * hours)
|
43
|
+
iso_str << "#{hours}H"
|
44
|
+
end
|
45
|
+
if seconds > 60 # more than a minute
|
46
|
+
minutes = seconds / 60
|
47
|
+
seconds -= (60 * minutes)
|
48
|
+
iso_str << "#{minutes}M"
|
49
|
+
end
|
50
|
+
iso_str << "#{seconds}S"
|
51
|
+
end
|
52
|
+
|
53
|
+
iso_str
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# rubocop:enable Metrics/MethodLength
|
58
|
+
# rubocop:enable Metrics/AbcSize
|
@@ -1,37 +1,37 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
module WinRM
|
18
|
-
# Wraps a PowerShell script to make it easy to Base64 encode for transport
|
19
|
-
class PowershellScript
|
20
|
-
attr_reader :text
|
21
|
-
|
22
|
-
# Creates a new PowershellScript object which can be used to encode
|
23
|
-
# PS scripts for safe transport over WinRM.
|
24
|
-
# @param [String] The PS script text content
|
25
|
-
def initialize(script)
|
26
|
-
@text = script
|
27
|
-
end
|
28
|
-
|
29
|
-
# Encodes the script so that it can be passed to the PowerShell
|
30
|
-
# --EncodedCommand argument.
|
31
|
-
# @return [String] The UTF-16LE base64 encoded script
|
32
|
-
def encoded
|
33
|
-
encoded_script = text.encode('UTF-16LE', 'UTF-8')
|
34
|
-
Base64.strict_encode64(encoded_script)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
# Wraps a PowerShell script to make it easy to Base64 encode for transport
|
19
|
+
class PowershellScript
|
20
|
+
attr_reader :text
|
21
|
+
|
22
|
+
# Creates a new PowershellScript object which can be used to encode
|
23
|
+
# PS scripts for safe transport over WinRM.
|
24
|
+
# @param [String] The PS script text content
|
25
|
+
def initialize(script)
|
26
|
+
@text = script
|
27
|
+
end
|
28
|
+
|
29
|
+
# Encodes the script so that it can be passed to the PowerShell
|
30
|
+
# --EncodedCommand argument.
|
31
|
+
# @return [String] The UTF-16LE base64 encoded script
|
32
|
+
def encoded
|
33
|
+
encoded_script = text.encode('UTF-16LE', 'UTF-8')
|
34
|
+
Base64.strict_encode64(encoded_script)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|