Class: WinRM::Shells::Elevated
- Inherits:
-
Object
- Object
- WinRM::Shells::Elevated
- Defined in:
- lib/chef-winrm/shells/elevated.rb
Overview
Runs PowerShell commands elevated via a scheduled task
Instance Attribute Summary collapse
-
#execution_timeout ⇒ Integer
Timeout for the task to be executed.
-
#interactive_logon ⇒ Bool
Using an interactive logon.
-
#password ⇒ String
The admin user password.
-
#username ⇒ String
The admin user name to execute the scheduled task as.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the shell if one is open.
-
#initialize(connection_opts, transport, logger) ⇒ Elevated
constructor
Create a new elevated shell.
-
#run(command, &block) ⇒ WinRM::Output
Run a command or PowerShell script elevated without any of the restrictions that WinRM puts in place.
Constructor Details
#initialize(connection_opts, transport, logger) ⇒ Elevated
Create a new elevated shell
30 31 32 33 34 35 36 37 38 |
# File 'lib/chef-winrm/shells/elevated.rb', line 30 def initialize(connection_opts, transport, logger) @logger = logger @username = connection_opts[:user] @password = connection_opts[:password] @interactive_logon = false @shell = Powershell.new(connection_opts, transport, logger) @winrm_file_transporter = WinRM::FS::Core::FileTransporter.new(@shell) @execution_timeout = 86_400 end |
Instance Attribute Details
#execution_timeout ⇒ Integer
Returns Timeout for the task to be executed.
50 51 52 |
# File 'lib/chef-winrm/shells/elevated.rb', line 50 def execution_timeout @execution_timeout end |
#interactive_logon ⇒ Bool
Returns Using an interactive logon.
47 48 49 |
# File 'lib/chef-winrm/shells/elevated.rb', line 47 def interactive_logon @interactive_logon end |
#password ⇒ String
Returns The admin user password.
44 45 46 |
# File 'lib/chef-winrm/shells/elevated.rb', line 44 def password @password end |
#username ⇒ String
Returns The admin user name to execute the scheduled task as.
41 42 43 |
# File 'lib/chef-winrm/shells/elevated.rb', line 41 def username @username end |
Instance Method Details
#close ⇒ Object
Closes the shell if one is open
68 69 70 |
# File 'lib/chef-winrm/shells/elevated.rb', line 68 def close @shell.close end |
#run(command, &block) ⇒ WinRM::Output
Run a command or PowerShell script elevated without any of the restrictions that WinRM puts in place.
58 59 60 61 62 63 64 65 |
# File 'lib/chef-winrm/shells/elevated.rb', line 58 def run(command, &block) # if an IO object is passed read it, otherwise assume the contents of the file were passed script_text = command.respond_to?(:read) ? command.read : command script_path = upload_elevated_shell_script(script_text) wrapped_script = wrap_in_scheduled_task(script_path, username, password) @shell.run(wrapped_script, &block) end |