When a scheduled task runs I would like to open a Powershell window on my desktop to tail the log file and watch the progress. Specifically I would like the task to open the window on my desktop and run Get-Content C:\LogFile.txt -Wait. When the task has finished I would like it to close the powershell window.
Is there a way to start a graphical window under another user? From what I have found, most commands will run under the privilege of the specified user but not create a window on their desktop.
It would be even nicer if it would run under whichever user is logged on when the task starts and not a hard coded user.
EDIT: So far I have the code below. I works to an extent. It creates the tailing window but when I call $p.kill() it kills the psexec process but not the powershell process. Can I send a Ctrl-C to the powershell window?
# start tailing the log
$psexec = 'c:\psexec.exe'
$arguments = '-i powershell.exe -windowstyle maximized -command "& {get-content c:\logs\task_log.log -wait}"'
$p = start-process $psexec -argumentlist $arguments -passthru
# start the task
Some-task.exe
# kill the tail
$p.kill()