From af0f267b5089098ded8c2c3e6b8495cbeb8cbcdd Mon Sep 17 00:00:00 2001 From: Arlo Louis O'Keeffe Date: Wed, 26 Aug 2015 00:15:03 +0200 Subject: [PATCH] Check if Schedule.Service com object is available --- .../communicators/winrm/scripts/elevated_shell.ps1.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb index 17767e436..77529aa76 100644 --- a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb +++ b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb @@ -1,5 +1,13 @@ param([String]$username, [String]$password, [String]$encoded_command) +$schedule = $null +Try { + $schedule = New-Object -ComObject "Schedule.Service" +} Catch [System.Management.Automation.PSArgumentException] { + powershell.exe -EncodedCommand $encoded_command + exit $LASTEXITCODE +} + $task_name = "WinRM_Elevated_Shell" $out_file = "$env:SystemRoot\Temp\WinRM_Elevated_Shell.log" @@ -50,7 +58,6 @@ $arguments = "/c powershell.exe -EncodedCommand $encoded_command > $out_file $task_xml = $task_xml.Replace("{arguments}", $arguments) $task_xml = $task_xml.Replace("{username}", $username) -$schedule = New-Object -ComObject "Schedule.Service" $schedule.Connect() $task = $schedule.NewTask($null) $task.XmlText = $task_xml