WinRb / winrm-elevated

Runs PowerShell commands as elevated over Windows Remote Management (WinRM) via a scheduled task
Apache License 2.0
27 stars 17 forks source link

winrm-v2 port #11

Closed mwrock closed 8 years ago

mwrock commented 8 years ago

This is work to get winrm-elevated working with new PSRP implementation. This initial port does not change any external interfaces other than the fact that the runner now takes a shell instead of an executor.

It is working with the exception of the exit code which seems to come over as 0 regardless of $LASTEXITCODE in the script.

Beyond fixing exit code, I'd like to change the interface so that runner actually IS a Shell. Assuming you require winrm-elevated WinRM::Connection.Shell(:elevated_powershell) will return a shell that implements run via a task and uses the username and password of the connection.

Alternatively you could "new up" a elevated shell with alternate credentials.

mwrock commented 8 years ago

Exitcode issue is resolved.

mwrock commented 8 years ago

The runner is now a Shell and can be used like:

conn.shell(:elevated) do |shell|
  shell.username = 'System'
  shell.password = nil
  shell.run('$PSVersionTable') do |stdout, stderr|
    STDOUT.print stdout
    STDERR.print stderr
  end
end