diff options
author | Tim Smith <tsmith@chef.io> | 2019-02-05 15:50:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-05 15:50:49 -0800 |
commit | fd764dff9f1cdaa1970aa4b10e8890a656175939 (patch) | |
tree | 1a89944e45ad77013acf31d89774ec739e233f5b /lib/chef/resource | |
parent | 7d8c3ba4b8aac21f7049ceed5a014e4cb556a6a4 (diff) | |
parent | 13fd78e7b6523d8f172c2173ae8153168c319ff6 (diff) | |
download | chef-fd764dff9f1cdaa1970aa4b10e8890a656175939.tar.gz |
Merge pull request #8167 from MsysTechnologiesllc/nimesh/MSYS-960_set_psscript_flags
powershell_script: Prefer user provided flags over the defaults
Diffstat (limited to 'lib/chef/resource')
-rw-r--r-- | lib/chef/resource/powershell_script.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index 95efadd4e6..53290c54f8 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -22,6 +22,21 @@ class Chef class PowershellScript < Chef::Resource::WindowsScript provides :powershell_script, os: "windows" + property :flags, String, + description: "A string that is passed to the Windows PowerShell command", + default: lazy { default_flags }, + coerce: proc { |input| + if input == default_flags + # Means there was no input provided, + # and should use defaults in this case + input + else + # The last occurance of a flag would override its + # previous one at the time of command execution. + [default_flags, input].join(" ") + end + } + description "Use the powershell_script resource to execute a script using the Windows PowerShell"\ " interpreter, much like how the script and script-based resources—bash, csh, perl, python,"\ " and ruby—are used. The powershell_script is specific to the Microsoft Windows platform"\ @@ -54,6 +69,27 @@ class Chef def self.get_default_attributes(opts) { convert_boolean_return: true } end + + # Options that will be passed to Windows PowerShell command + def default_flags + return "" if Chef::Platform.windows_nano_server? + + # Execution policy 'Bypass' is preferable since it doesn't require + # user input confirmation for files such as PowerShell modules + # downloaded from the Internet. However, 'Bypass' is not supported + # prior to PowerShell 3.0, so the fallback is 'Unrestricted' + execution_policy = Chef::Platform.supports_powershell_execution_bypass?(run_context.node) ? "Bypass" : "Unrestricted" + + [ + "-NoLogo", + "-NonInteractive", + "-NoProfile", + "-ExecutionPolicy #{execution_policy}", + # PowerShell will hang if STDIN is redirected + # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected + "-InputFormat None", + ].join(" ") + end end end end |