Powershell – Adding/Enabling windows feature using chef

chefcookbookpowershell

I am writing chef cookbook to add/enable some of the windows feature. For enabling I am using powershell_script resource and below is the powershell script.

Import-Module Servermanager
Add-WindowsFeature Print-LPD-Service

For some reason, during chef-client run windows feature is not enabled. But the recipe ran successfully.

When I manually executed the command in powershell shell it works fine.

I am not aware of any security settings to be enabled to achieve this requirement. So, how we can enable windows feature using chef. Any pointers will be helpful.

Best Answer

Used windows_feature resource from windows cookbook instead of powershell_script resource to enable the features.

windows_feature 'Printing-LPDPrintService' do
  action :install
  not_if  { Registry.key_exists?('HKLM\System\CurrentControlSet\services\LPDSVC') }
end
Related Topic