class Chef::PowerShell

Attributes

errors[R]
result[R]

Public Class Methods

new(script) click to toggle source

Run a command under PowerShell via a managed (.NET) COM interop API. This implementation requires the managed dll to be registered on the target machine.

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 35
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 40
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 47
def exec(script)
  ps = WIN32OLE.new("Chef.PowerShell")
  outcome = ps.ExecuteScript(script)
  hashed_outcome = Chef::JSONCompat.parse(outcome)
  @result = Chef::JSONCompat.parse(hashed_outcome["result"])
  @errors = hashed_outcome["errors"]
end