diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/powershell_script.rb | 13 | ||||
-rw-r--r-- | lib/chef/resource/powershell_script.rb | 8 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 49d800b6d2..8360dd873b 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -54,7 +54,18 @@ class Chef def interpreter_path # Powershell.exe is always in "v1.0" folder (for backwards compatibility) - Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", interpreter) + # pwsh is the other interpreter and we will assume that it is on the path. + # It will exist in different folders depending on the installed version. + # There can also be multiple versions installed. Depending on how it was installed, + # there might be a registry entry pointing to the installation path. The key will + # differ depending on version and architecture. It seems best to let the PATH + # determine the file path to use since that will provide the same pwsh.exe one + # would invoke from any shell. + if interpreter == "powershell" + Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", "#{interpreter}.exe") + else + interpreter + end end def code diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index 7699c0a976..5c9b540f55 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -22,11 +22,18 @@ class Chef class PowershellScript < Chef::Resource::WindowsScript unified_mode true + set_guard_inherited_attributes(:interpreter) + provides :powershell_script, os: "windows" property :flags, String, description: "A string that is passed to the Windows PowerShell command" + property :interpreter, String, + default: "powershell", + equal_to: %w{powershell pwsh}, + description: "The interpreter type, `powershell` or `pwsh` (PowerShell Core)" + property :convert_boolean_return, [true, false], default: false, description: <<~DESC @@ -62,7 +69,6 @@ class Chef def initialize(*args) super - @interpreter = "powershell.exe" @default_guard_interpreter = resource_name end |