diff --git a/recipes/powershell2.rb b/recipes/powershell2.rb index 57d2a43..9dce4de 100644 --- a/recipes/powershell2.rb +++ b/recipes/powershell2.rb @@ -26,34 +26,24 @@ require 'chef/win32/version' windows_version = Chef::ReservedNames::Win32::Version.new + nt_version = node['platform_version'].to_f - if (windows_version.windows_server_2012? || windows_version.windows_8?) && windows_version.core? - # Windows Server 2012 Core does not come with Powershell 2.0 enabled - windows_feature 'MicrosoftWindowsPowerShellV2' do - action :install - end - windows_feature 'MicrosoftWindowsPowerShellV2-WOW64' do - action :install - only_if { node['kernel']['machine'] == 'x86_64' } - end + include_recipe 'ms_dotnet::ms_dotnet2' - elsif (windows_version.windows_server_2008_r2? || windows_version.windows_7?) && windows_version.core? - # Windows Server 2008 R2 Core does not come with .NET or Powershell 2.0 enabled - include_recipe 'ms_dotnet::ms_dotnet2' + if windows_version.core? && nt_version.between?(6.1, 6.2) + feature_suffix = 'V2' if nt_version == 6.2 - windows_feature 'MicrosoftWindowsPowerShell' do + windows_feature "MicrosoftWindowsPowerShell#{feature_suffix}" do action :install end - windows_feature 'MicrosoftWindowsPowerShell-WOW64' do + + windows_feature "MicrosoftWindowsPowerShell#{feature_suffix}-WOW64" do action :install only_if { node['kernel']['machine'] == 'x86_64' } end - elsif windows_version.windows_server_2008? || windows_version.windows_server_2003_r2? || - windows_version.windows_server_2003? || windows_version.windows_xp? - - include_recipe 'ms_dotnet::ms_dotnet2' - + # WMF 2.0 is required for XP and Windows Server 2003 + elsif nt_version.between?(5.1, 5.2) # Reboot if user specifies doesn't specify no_reboot include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot' diff --git a/recipes/powershell3.rb b/recipes/powershell3.rb index 977594d..ad1b843 100644 --- a/recipes/powershell3.rb +++ b/recipes/powershell3.rb @@ -24,10 +24,11 @@ case node['platform'] when 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - - if windows_version.windows_server_2008? || windows_version.windows_server_2008_r2? || windows_version.windows_7? + nt_version = node['platform_version'].to_f + # Powershell 3.0 is only compatible with: + # * Windows NT 6.0 server (Windows Server 2008 SP2 not vista) + # * Windows NT 6.1 (Windows Server 2008R2 & Windows 7.1) + if (nt_version == 6.0 && node['kernel']['os_info']['product_type'] != 0x1) || nt_version == 6.1 # For Windows Server 2008 ensure that Powershell 2 is already installed and so is BITS 4.0 if windows_version.windows_server_2008? diff --git a/recipes/powershell4.rb b/recipes/powershell4.rb index 7f3bea2..9520c0e 100644 --- a/recipes/powershell4.rb +++ b/recipes/powershell4.rb @@ -22,10 +22,12 @@ # http://www.microsoft.com/en-us/download/details.aspx?id=40855 if node['platform'] == 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - if windows_version.windows_server_2008_r2? || windows_version.windows_7? || windows_version.windows_server_2012? + nt_version = node['platform_version'].to_f + # WMF 4.0 is only compatible with: + # * Windows NT 6.1 (Windows Server 2008R2 & Windows 7.1) + # * Windows NT 6.2 Server (Windows Server 2012 not Windows 8) + if nt_version == 6.1 || (nt_version == 6.2 && node['kernel']['os_info']['product_type'] != 0x1) # Ensure .NET 4.5 is installed or installation will fail silently per Microsoft. fail 'Attribute ms_dotnet.v4.version is not configured to install .NET4.5 as required for Powershell4' if node.default['ms_dotnet']['v4']['version'] < '4.5' diff --git a/recipes/powershell5.rb b/recipes/powershell5.rb index 2ccda0f..c819c2e 100644 --- a/recipes/powershell5.rb +++ b/recipes/powershell5.rb @@ -26,11 +26,10 @@ case node['platform'] when 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - - if windows_version.windows_server_2012_r2? || windows_version.windows_8_1? + nt_version = node['platform_version'].to_f + # Handle WMFC install on 2012R2 and 8.1 only (yet) + if nt_version == 6.3 include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot' windows_package 'Windows Management Framework Core 5.0' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e667e88..ecf602b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,10 @@ require 'chefspec' require 'chefspec/berkshelf' require 'helpers/matchers' + +RSpec.configure do |config| + config.before :each do + allow(::Kernel).to receive('require').and_call_original + allow(::Kernel).to receive('require').with('chef/win32/api/system') + end +end \ No newline at end of file