Module: Chef::Mixin::PowershellOut

Includes:
ShellOut, WindowsArchitectureHelper
Included in:
DSL::Universal
Defined in:
lib/chef/mixin/powershell_out.rb

Instance Method Summary collapse

Methods included from WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Instance Method Details

#powershell_out(*command_args) ⇒ Mixlib::Shellout

Run a command under powershell with the same API as shell_out. The options hash is extended to take an "architecture" flag which can be set to :i386 or :x86_64 to force the windows architecture.

Parameters:

  • script (String)

    script to run

  • interpreter (Symbol)

    the interpreter type, :powershell or :pwsh

  • options (Hash)

    options hash

Returns:

  • (Mixlib::Shellout)

    mixlib-shellout object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
# File 'lib/chef/mixin/powershell_out.rb', line 34

def powershell_out(*command_args)
  script = command_args.first
  options = command_args.last.is_a?(Hash) ? command_args.last : nil
  interpreter = command_args[1].is_a?(Symbol) ? command_args[1] : :powershell

  raise ArgumentError, "Expected interpreter of :powershell or :pwsh" unless %i{powershell pwsh}.include?(interpreter)

  run_command_with_os_architecture(script, interpreter, options)
end

#powershell_out!(*command_args) ⇒ Mixlib::Shellout

Run a command under powershell with the same API as shell_out! (raises exceptions on errors)

Parameters:

  • script (String)

    script to run

  • interpreter (Symbol)

    the interpreter type, :powershell or :pwsh

  • options (Hash)

    options hash

Returns:

  • (Mixlib::Shellout)

    mixlib-shellout object



51
52
53
54
55
# File 'lib/chef/mixin/powershell_out.rb', line 51

def powershell_out!(*command_args)
  cmd = powershell_out(*command_args)
  cmd.error!
  cmd
end