class Inspec::Resources::PowershellScript
Public Class Methods
new(script)
click to toggle source
Calls superclass method
Inspec::Resources::Cmd::new
# File lib/inspec/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
Public Instance Methods
exist?()
click to toggle source
we cannot determine if a command exists, because that does not work for scripts
# File lib/inspec/resources/powershell.rb, line 40 def exist? nil end
strip()
click to toggle source
Removes leading and trailing whitespace from stdout
# File lib/inspec/resources/powershell.rb, line 45 def strip result.stdout&.strip end
to_s()
click to toggle source
# File lib/inspec/resources/powershell.rb, line 49 def to_s "Powershell" end