Powershell

使用廚師添加/啟用視窗功能

  • January 9, 2014

我正在編寫廚師食譜以添加/啟用某些 Windows 功能。為了啟用我正在使用powershell_script資源,下面是 powershell 腳本。

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

由於某種原因,在 chef-client 執行期間未啟用 windows 功能。但配方執行成功。

當我在 powershell shell 中手動執行命令時,它工作正常。

我不知道要啟用任何安全設置來實現此要求。那麼,我們如何使用 Chef 啟用 Windows 功能。任何指針都會有所幫助。

使用食譜中的資源而不是windows_feature資源來啟用這些功能。windows``powershell_script

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

如果它通過互動式 shell 執行,則可能不允許您在該機器上執行腳本。

您可能需要將其放在腳本的開頭:

Set-ExecutionPolicy Unrestricted -Confirm:$false

該腳本需要以管理員身份執行。

引用自:https://serverfault.com/questions/565770