class Chef::PowerShell

Attributes

errors[R]
result[R]

Public Class Methods

new(script) click to toggle source

Run a command under PowerShell via FFI This implementation requires the managed dll and native wrapper to be in the library search path on Windows (i.e. c:windowssystem32 or in the same location as ruby.exe).

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

@param script [String] script to run @return [Object] output

# File lib/chef/powershell.rb, line 36
def initialize(script)
  raise "Chef::PowerShell can only be used on the Windows platform." unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
  exec(script)
end

Public Instance Methods

error?() click to toggle source
# File lib/chef/powershell.rb, line 41
def error?
  return true if errors.count > 0
  false
end

Private Instance Methods

exec(script) click to toggle source
# File lib/chef/powershell.rb, line 48
def exec(script)
  FFI.ffi_lib "Chef.PowerShell.Wrapper.dll"
  FFI.attach_function :execute_powershell, :ExecuteScript, [:string], :pointer
  execution = FFI.execute_powershell(script).read_utf16string
  hashed_outcome = Chef::JSONCompat.parse(execution)
  @result = Chef::JSONCompat.parse(hashed_outcome["result"])
  @errors = hashed_outcome["errors"]
end