class LegacyFacter::Util::Parser::PowershellParser

Executes and parses the key value output of Powershell scripts

Public Instance Methods

parse_results() click to toggle source

Returns a hash of facts from powershell output

# File lib/facter/custom_facts/util/parser.rb, line 182
def parse_results
  powershell =
    if File.readable?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
    elsif File.readable?("#{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}\""
  stdout, stderr = Facter::Core::Execution.execute_command(shell_command)
  log_stderr(stderr, shell_command, filename)
  parse_executable_output(stdout)
end