diff options
author | Steven Murawski <steven.murawski@gmail.com> | 2016-06-20 14:00:48 -0500 |
---|---|---|
committer | Steven Murawski <steven.murawski@gmail.com> | 2016-06-20 14:08:03 -0500 |
commit | 711ca02bf1823d5653841a100978c94f2229f376 (patch) | |
tree | bec1654bf10c1289e0f2baec604bceaea7e25372 /lib | |
parent | b3ba655e679e93e945f88ba5940245adbca8c876 (diff) | |
download | ohai-711ca02bf1823d5653841a100978c94f2229f376.tar.gz |
update powershell compatible version parsing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/plugins/powershell.rb | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/ohai/plugins/powershell.rb b/lib/ohai/plugins/powershell.rb index 59365b65..08e72610 100644 --- a/lib/ohai/plugins/powershell.rb +++ b/lib/ohai/plugins/powershell.rb @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +require "base64" Ohai.plugin(:Powershell) do provides "languages/powershell" @@ -46,7 +47,7 @@ Ohai.plugin(:Powershell) do powershell[:serialization_version] = version_info["SerializationVersion"] powershell[:clr_version] = version_info["CLRVersion"] powershell[:build_version] = version_info["BuildVersion"] - powershell[:compatible_versions] = parse_compatible_versions(version_info["PSCompatibleVersions"]) + powershell[:compatible_versions] = parse_compatible_versions powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"] languages[:powershell] = powershell unless powershell.empty? end @@ -55,12 +56,28 @@ Ohai.plugin(:Powershell) do end end - def parse_compatible_versions(versions_str) - if versions_str - if versions_str.strip.start_with?("{") && versions_str.end_with?("}") - versions = versions_str.gsub(/[{}\s]+/, "").split(",") - versions if versions.length - end + def version_command + [ + "$progresspreference = 'silentlycontinue'", + "$PSVersionTable.PSCompatibleVersions | foreach {$_.tostring()}", + ].join("; ") + end + + def powershell_command + ["powershell.exe", + "-NoLogo", + "-NonInteractive", + "-NoProfile", + "-Command", + ].join(" ") + end + + def parse_compatible_versions + so = shell_out("#{powershell_command} \"#{version_command}\"") + versions = [] + so.stdout.strip.each_line do |line| + versions << line.strip end + versions end end |