module Chef::Mixin::PowershellExec

Public Instance Methods

powershell_exec(script, interpreter = :powershell) click to toggle source

Run a command under PowerShell via a managed (.NET) API.

Requires: .NET Framework 4.0 or higher on the target machine.

@param script [String] script to run @param interpreter [Symbol] the interpreter type, `:powershell` or `:pwsh` @return [Chef::PowerShell] output

# File lib/chef/mixin/powershell_exec.rb, line 108
def powershell_exec(script, interpreter = :powershell)
  case interpreter
  when :powershell
    Chef::PowerShell.new(script)
  when :pwsh
    Chef::Pwsh.new(script)
  else
    raise ArgumentError, "Expected interpreter of :powershell or :pwsh"
  end
end
powershell_exec!(script, interpreter = :powershell) click to toggle source

The same as the powershell_exec method except this will raise Chef::PowerShell::CommandFailed if the command fails

# File lib/chef/mixin/powershell_exec.rb, line 121
def powershell_exec!(script, interpreter = :powershell)
  cmd = powershell_exec(script, interpreter)
  cmd.error!
  cmd
end