Check if Schedule.Service com object is available

This commit is contained in:
Arlo Louis O'Keeffe 2015-08-26 00:15:03 +02:00
parent c84e05fd06
commit af0f267b50
1 changed files with 8 additions and 1 deletions

View File

@ -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