我正在写厨师食谱添加/启用一些窗口function。 为了启用我使用powershell_script资源,下面是PowerShell脚本。
Import-Module Servermanager Add-WindowsFeature Print-LPD-Service
出于某种原因,在厨师客户端运行窗口function未启用。 但配方运行成功。
当我手动执行在PowerShell shell中的命令,它工作正常。
我不知道要启用任何安全设置来实现此要求。 那么,我们如何使用厨师启用windowsfunction。 任何指针都会有所帮助。
使用windows Cookbook中的powershell_script资源而不是powershell_script资源来启用这些function。
windows_feature 'Printing-LPDPrintService' do action :install not_if { Registry.key_exists?('HKLM\System\CurrentControlSet\services\LPDSVC') } end
如果它通过交互式shell运行,那么可能不允许在该机器上运行脚本。
您可能需要将其放在脚本的开头:
Set-ExecutionPolicy Unrestricted -Confirm:$false
该脚本需要以pipe理员身份运行。