Skip to content

Commit

Permalink
Use path to locate powershell.exe & remove deps on Windows cookbook
Browse files Browse the repository at this point in the history
The only reason we use to have a dependency on Windows cookbook was the
locate_sysnative_cmd helper.
However this helper is not a "which" or "where", it just check whether
the given path exist under the "native" system path.
In our case, powershell.exe is not located there, but deeper in the
directory structure, so "powershell.exe" was returned.
So we don't need this helper and the Windows cookbook :)
  • Loading branch information
Annih committed Jul 30, 2024
1 parent da4cebc commit 2abea97
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
7 changes: 1 addition & 6 deletions libraries/base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module BaseProvider
require 'yaml'
require 'base64'
include Chef::Mixin::ShellOut
include Windows::Helper

def self.uri_to_wsus_endpoint_params(uri)
uri = URI uri
Expand All @@ -46,10 +45,6 @@ def endpoint_params
@endpoint ||= @new_resource.endpoint ? WsusServer::BaseProvider.uri_to_wsus_endpoint_params(@new_resource.endpoint) : ''
end

def powershell
locate_sysnative_cmd('powershell.exe')
end

def powershell_out64(cmd, timeout = 300)
flags = [
# Hides the copyright banner at startup.
Expand All @@ -70,7 +65,7 @@ def powershell_out64(cmd, timeout = 300)
# Use powershell with absolute path to the binary (it's the same path for all versions)
# Use the locate_sysnative helper to target the right powershell binary
# => https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187.aspx
cmd = shell_out "#{powershell} #{flags.join(' ')} -EncodedCommand #{encoded_command}", timeout: timeout
cmd = shell_out "powershell.exe #{flags.join(' ')} -EncodedCommand #{encoded_command}", timeout: timeout
cmd.error!
raise 'Invalid syntax in PowershellScript' if cmd.stderr && cmd.stderr.include?('ParserError')
cmd
Expand Down
1 change: 0 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
description 'Installs wsus server'
version '2.3.2'
supports 'windows'
depends 'windows'

chef_version '>= 12.1'
source_url 'https://github.com/criteo-cookbooks/wsus-server'
Expand Down

0 comments on commit 2abea97

Please sign in to comment.