Method: Beaker::DSL::Wrappers#powershell
- Defined in:
- lib/beaker/dsl/wrappers.rb
#powershell(command, args = {}) ⇒ Command
Returns a Command object for executing powershell commands on a host
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/beaker/dsl/wrappers.rb', line 126 def powershell(command, args={}) ps_opts = { 'ExecutionPolicy' => 'Bypass', 'InputFormat' => 'None', 'NoLogo' => '', 'NoProfile' => '', 'NonInteractive' => '' } encoded = false ps_opts.merge!(args) ps_args = [] # determine if the command should be encoded if ps_opts.has_key?('EncodedCommand') v = ps_opts.delete('EncodedCommand') # encode the commend if v is true, nil or empty encoded = v || v.eql?('') || v.nil? end ps_opts.each do |k, v| if v.eql?('') or v.nil? ps_args << "-#{k}" else ps_args << "-#{k} #{v}" end end # may not have a command if executing a file if command && !command.empty? if encoded ps_args << "-EncodedCommand #{encode_command(command)}" else ps_args << "-Command #{command}" end end Command.new("powershell.exe", ps_args) end |