diff --git a/plugins/communicators/winrm/communicator.rb b/plugins/communicators/winrm/communicator.rb
index ade021aad..ee8cd9801 100644
--- a/plugins/communicators/winrm/communicator.rb
+++ b/plugins/communicators/winrm/communicator.rb
@@ -43,6 +43,7 @@ module VagrantPlugins
# Got it! Let the user know what we're connecting to.
@machine.ui.detail("WinRM address: #{shell.host}:#{shell.port}")
@machine.ui.detail("WinRM username: #{shell.username}")
+ @machine.ui.detail("WinRM execution_time_limit: #{shell.execution_time_limit}")
@machine.ui.detail("WinRM transport: #{shell.config.transport}")
last_message = nil
@@ -218,7 +219,8 @@ module VagrantPlugins
"powershell -executionpolicy bypass -file \"#{guest_script_path}\" " +
"-username \"#{shell.username}\" -password \"#{shell.password}\" " +
- "-encoded_command \"#{wrapped_encoded_command}\""
+ "-encoded_command \"#{wrapped_encoded_command}\" " +
+ "-execution_time_limit \"#{shell.execution_time_limit}\""
end
# Handles the raw WinRM shell result and converts it to a
diff --git a/plugins/communicators/winrm/config.rb b/plugins/communicators/winrm/config.rb
index 79901d503..3387ca142 100644
--- a/plugins/communicators/winrm/config.rb
+++ b/plugins/communicators/winrm/config.rb
@@ -11,6 +11,7 @@ module VagrantPlugins
attr_accessor :timeout
attr_accessor :transport
attr_accessor :ssl_peer_verification
+ attr_accessor :execution_time_limit
def initialize
@username = UNSET_VALUE
@@ -23,6 +24,7 @@ module VagrantPlugins
@timeout = UNSET_VALUE
@transport = UNSET_VALUE
@ssl_peer_verification = UNSET_VALUE
+ @execution_time_limit = UNSET_VALUE
end
def finalize!
@@ -37,6 +39,7 @@ module VagrantPlugins
@retry_delay = 2 if @retry_delay == UNSET_VALUE
@timeout = 1800 if @timeout == UNSET_VALUE
@ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE
+ @execution_time_limit = "PT2H" if @execution_time_limit == UNSET_VALUE
end
def validate(machine)
@@ -49,6 +52,7 @@ module VagrantPlugins
errors << "winrm.max_tries cannot be nil." if @max_tries.nil?
errors << "winrm.retry_delay cannot be nil." if @max_tries.nil?
errors << "winrm.timeout cannot be nil." if @timeout.nil?
+ errors << "winrm.execution_time_limit cannot be nil." if @execution_time_limit.nil?
unless @ssl_peer_verification == true || @ssl_peer_verification == false
errors << "winrm.ssl_peer_verification must be a boolean."
end
diff --git a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb
index a33644bd8..3d02f9ea9 100644
--- a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb
+++ b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb
@@ -1,4 +1,4 @@
-param([String]$username, [String]$password, [String]$encoded_command)
+param([String]$username, [String]$password, [String]$encoded_command, [String]$execution_time_limit)
# Try to get the Schedule.Service object. If it fails, we are probably
# on an older version of Windows. On old versions, we can just execute
@@ -44,7 +44,7 @@ $task_xml = @'
false
false
false
- PT2H
+ {execution_time_limit}
4
@@ -60,6 +60,7 @@ $arguments = "/c powershell.exe -EncodedCommand $encoded_command > $out_file
$task_xml = $task_xml.Replace("{arguments}", $arguments)
$task_xml = $task_xml.Replace("{username}", $username)
+$task_xml = $task_xml.Replace("{execution_time_limit}", $execution_time_limit)
$schedule.Connect()
$task = $schedule.NewTask($null)
diff --git a/plugins/communicators/winrm/shell.rb b/plugins/communicators/winrm/shell.rb
index 48c1bc6d8..683358983 100644
--- a/plugins/communicators/winrm/shell.rb
+++ b/plugins/communicators/winrm/shell.rb
@@ -38,6 +38,7 @@ module VagrantPlugins
attr_reader :port
attr_reader :username
attr_reader :password
+ attr_reader :execution_time_limit
attr_reader :config
def initialize(host, port, config)
@@ -48,6 +49,7 @@ module VagrantPlugins
@port = port
@username = config.username
@password = config.password
+ @execution_time_limit = config.execution_time_limit
@config = config
end
diff --git a/test/unit/plugins/communicators/winrm/communicator_test.rb b/test/unit/plugins/communicators/winrm/communicator_test.rb
index 829170bd6..e571ab020 100644
--- a/test/unit/plugins/communicators/winrm/communicator_test.rb
+++ b/test/unit/plugins/communicators/winrm/communicator_test.rb
@@ -21,6 +21,7 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
before do
allow(shell).to receive(:username).and_return('vagrant')
allow(shell).to receive(:password).and_return('password')
+ allow(shell).to receive(:execution_time_limit).and_return('PT2H')
end
describe ".wait_for_ready" do
@@ -88,7 +89,7 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
expect(shell).to receive(:upload).with(kind_of(String), "c:/tmp/vagrant-elevated-shell.ps1")
expect(shell).to receive(:powershell) do |cmd|
expect(cmd).to eq("powershell -executionpolicy bypass -file \"c:/tmp/vagrant-elevated-shell.ps1\" " +
- "-username \"vagrant\" -password \"password\" -encoded_command \"ZABpAHIAOwAgAGUAeABpAHQAIAAkAEwAQQBTAFQARQBYAEkAVABDAE8ARABFAA==\"")
+ "-username \"vagrant\" -password \"password\" -encoded_command \"ZABpAHIAOwAgAGUAeABpAHQAIAAkAEwAQQBTAFQARQBYAEkAVABDAE8ARABFAA==\" -execution_time_limit \"PT2H\"")
end.and_return({ exitcode: 0 })
expect(subject.execute("dir", { elevated: true })).to eq(0)
end