Method: Inspec::Resources::PowershellScript#initialize
- Defined in:
- lib/resources/powershell.rb
#initialize(script) ⇒ PowershellScript
Returns a new instance of PowershellScript.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/resources/powershell.rb', line 20 def initialize(script) # PowerShell is the default shell on Windows, use the `command` resource return super(script) if inspec.os.windows? unless inspec.command('pwsh').exist? raise Inspec::Exceptions::ResourceSkipped, 'Can not find `pwsh` command' end # Prevent progress stream from leaking into stderr command = "$ProgressPreference='SilentlyContinue';" + script # Encode as Base64 to remove any quotes/escapes/etc issues command = command.encode('UTF-16LE', 'UTF-8') command = Base64.strict_encode64(command) # Use the `command` resource to execute the command via `pwsh` super("pwsh -encodedCommand '#{command}'") end |