class Inspec::Resources::Powershell
def exist?
def exist? nil end
def initialize(script)
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
def resource_id
def resource_id "Powershell" end
def strip
def strip result.stdout&.strip end
def to_s
def to_s "Powershell" end