I am trying to get a specific restart command to a cmd.exe window at a particular time in the day everyday in order to restart the server it is running.
My Action in Task Scheduler is currently:
Powershell.exe -ExecutionPolicy Bypass -File C:\Rustide\restart.ps1 -verbose >> C:\Rustide\myscript.log 2>&1"
It does not actually create the log, so I do not think that powershell is getting launched. Since I need the command to run and find a window on my profile, it is set to run off my profile. The script works perfectly when I execute it on my own. Is there a reason or security measure that is built in to task scheduler that is not letting me do this? If so, is there a good alternative?
I have tried this with the only when user is logged on, whether user is logged on or not, with highest privileges, etc. Nothing seems to work.
PowerShell Code
Start-Transcript -Path C:\Rustide\restart.log
Import-Module WASP
Select-Window | Where { $_.Title -Like '*OSF*Oxide' } | Set-WindowActive | Send-Keys 'restart'
start-sleep -seconds 2
Log from executing through task scheduler.
**********************
Windows PowerShell transcript start
Start time: 20160725080935
Username: OSF-WS2012\OSF
RunAs User: OSF-WS2012\OSF
Machine: OSF-WS2012 (Microsoft Windows NT 6.3.9600.0)
Host Application: Powershell.exe -ExecutionPolicy Bypass -File C:\Rustide\restart.ps1 Start-Transcript -Path C:\Rustide\restart.log
Process ID: 10588
**********************
Transcript started, output file is C:\Rustide\restart.log
PS>$global:?
True
**********************
Windows PowerShell transcript end
End time: 20160725080937
**********************