class Inspec::Resources::PowershellScript

def exist?

we cannot determine if a command exists, because that does not work for scripts
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 strip

Removes leading and trailing whitespace from stdout
def strip
  result.stdout&.strip
end

def to_s

def to_s
  'Powershell'
end