Merge pull request #6195 from ArloL/fix-windows-xp-shell-provisioning

Check if Schedule.Service com object is available
This commit is contained in:
Mitchell Hashimoto 2015-11-18 12:52:24 -08:00
commit 34dc9e237e
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