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

Erase old tasks before running #37

Closed tarraschk closed 4 years ago

tarraschk commented 4 years ago

This Pull Requests add some cleaning to the established WinRM connections.

The WinRM elevated mode uses ScheduledTasks to execute commands in elevated mode. However, sometimes, the WinRM connection "leaves" the ScheduledTask there without cleaning it.

We noticed this behaviour since the introduction of the GUID in the ScheduledTasks names.

This PR lets you configure a maximum idle time in seconds, and when we create a new winrm-elevated-shell, we clean any ScheduledTask that might have been created earlier than NOW-MAXIMUM_IDLE_TIME.

By default, this maximum idle time is set at 86400 (1 day), so that any winrm-elevated-shell will clean ScheduledTasks created at least 1 day ago.

Unit tests have been added for the integration environment to test this.

tarraschk commented 4 years ago

Based on discussions with @fwininger I changed my code to use the same execution_timeout parameter as the limit to clean old tasks :)

fwininger commented 4 years ago

@mwrock can you review this PR ?

tarraschk commented 4 years ago

Note: additional tests show it works only on Windows Server 2012+

We are looking at modifications to make it compatible with older versions

tarraschk commented 4 years ago

The code is now compatible with older Windows versions

fwininger commented 4 years ago

thanks @mwrock