Class: Inspec::Resources::PowershellScript

Inherits:
Cmd
  • Object
show all
Defined in:
lib/resources/powershell.rb

Direct Known Subclasses

LegacyPowershellScript, VBScript

Instance Attribute Summary

Attributes inherited from Cmd

#command

Instance Method Summary collapse

Methods inherited from Cmd

#exit_status, #result, #stderr, #stdout

Constructor Details

#initialize(script) ⇒ PowershellScript

Returns a new instance of PowershellScript.



19
20
21
22
23
24
25
26
27
# File 'lib/resources/powershell.rb', line 19

def initialize(script)
  unless inspec.os.windows?
    super('')
    return skip_resource 'The `script` resource is not supported on your OS yet.'
  end
  # 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

Instance Method Details

#exist?Boolean

we cannot determine if a command exists, because that does not work for scripts

Returns:

  • (Boolean)


30
31
32
# File 'lib/resources/powershell.rb', line 30

def exist?
  nil
end

#stripObject

Removes leading and trailing whitespace from stdout



35
36
37
# File 'lib/resources/powershell.rb', line 35

def strip
  result.stdout&.strip
end

#to_sObject



39
40
41
# File 'lib/resources/powershell.rb', line 39

def to_s
  'Powershell'
end