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.

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
|improve this answer|||||
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.

|improve this answer|||||
  • 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 8 '14 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.