Class: Facter::Util::Parser::PowershellParser

Inherits:
Base
  • Object
show all
Defined in:
lib/facter/util/parser.rb

Overview

Executes and parses the key value output of Powershell scripts

Instance Attribute Summary

Attributes inherited from Base

#filename

Instance Method Summary collapse

Methods inherited from Base

#content, #initialize, #results

Constructor Details

This class inherits a constructor from Facter::Util::Parser::Base

Instance Method Details

#parse_resultsObject

Returns a hash of facts from powershell output



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/facter/util/parser.rb', line 141

def parse_results
  powershell =
    if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
    elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
    else
      'powershell.exe'
    end

  shell_command = "\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\""
  output = Facter::Core::Execution.exec(shell_command)
  KeyValuePairOutputFormat.parse(output)
end