Sha256: 39f0b74e77b1bf5d9c7a2a1140642a287683e2177dfdef743743db850e399f94

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH

module Inspec::Resources
  class PowershellScript < Cmd
    name 'powershell'
    supports platform: 'windows'
    desc 'Use the powershell InSpec audit resource to test a Windows PowerShell script on the Microsoft Windows platform.'
    example "
      script = <<-EOH
        # your powershell script
      EOH

      describe powershell(script) do
        its('matcher') { should eq 'output' }
      end
    "

    def initialize(script)
      # since WinRM 2.0 and the default use of powershell for local execution in
      # train, we do not need to wrap the script here anymore
      super(script)
    end

    # we cannot determine if a command exists, because that does not work for scripts
    def exist?
      nil
    end

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

    def to_s
      'Powershell'
    end
  end

  # this is deprecated syntax and will be removed in future versions
  class LegacyPowershellScript < PowershellScript
    name 'script'

    def initialize(script)
      deprecated
      super(script)
    end

    def deprecated
      warn '[DEPRECATION] `script(script)` is deprecated.  Please use `powershell(script)` instead.'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
inspec-2.1.0 lib/resources/powershell.rb
inspec-2.0.45 lib/resources/powershell.rb