How to do it...

Let's start with an analysis of the run method of the module to understand how it works:

def run  raise "Powershell not available" if ! have_powershell?    script = make_subs(read_script(datastore['SCRIPT']), process_subs(datastore['SUBSTITUTIONS']))  print_status psh_exec(script)  print_good 'Finished!'end
  1. First, it verifies that the requirements are met, in this case whether PowerShell is available; if not it raises an exception:
raise "Powershell not available" if ! have_powershell?
  1. Next, it reads and preprocesses the PowerShell script supplied and saves the result in a variable named script:
script = make_subs(read_script(datastore['SCRIPT']), process_subs(datastore['SUBSTITUTIONS']))
  1. Finally, it calls the psh_exec method ...

Get Metasploit Penetration Testing Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.