1

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.

vareda
  • 70
  • 1
  • 7

2 Answers2

2

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
vareda
  • 70
  • 1
  • 7
0

If it ran via the interactive shell, then you might not be allowed to run scripts on that machine.

You might need to put this at the beginning of your script:

Set-ExecutionPolicy Unrestricted -Confirm:$false

The script needs to be run as an Administrator.

Vasili Syrakis
  • 4,435
  • 3
  • 21
  • 29
  • When using `powershell_script` resource, its executed as non-interactive. The command executed from chef-client log is `execute "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None -File $TEMP_PATH` – vareda Jan 08 '14 at 05:36