diff --git a/provisioner/powershell/elevated.go b/provisioner/powershell/elevated.go index 80bdc005a..d2c23f757 100644 --- a/provisioner/powershell/elevated.go +++ b/provisioner/powershell/elevated.go @@ -14,7 +14,7 @@ type elevatedOptions struct { var elevatedTemplate = template.Must(template.New("ElevatedCommand").Parse(` $name = "{{.TaskName}}" -$log = "$env:TEMP\$name.out" +$log = "$env:SystemRoot\Temp\$name.out" $s = New-Object -ComObject "Schedule.Service" $s.Connect() $t = $s.NewTask($null) @@ -53,7 +53,7 @@ $t.XmlText = @' cmd - /c powershell.exe -EncodedCommand {{.EncodedCommand}} > %TEMP%\{{.TaskName}}.out 2>&1 + /c powershell.exe -EncodedCommand {{.EncodedCommand}} > %SYSTEMROOT%\Temp\{{.TaskName}}.out 2>&1 @@ -81,5 +81,8 @@ do { } } while (!($t.state -eq 3)) $result = $t.LastTaskResult +if (Test-Path $log) { + Remove-Item $log -Force -ErrorAction SilentlyContinue | Out-Null +} [System.Runtime.Interopservices.Marshal]::ReleaseComObject($s) | Out-Null exit $result`))