windows - C# Console Application run in Powershell viaTask Scheduler -


i'm trying console application run via powersheell/task scheduler.

if open powershell , manually run .\startreport.ps1 works. console application doesn't open, runs silently in background.

however, when go create task via task scheduler, fails... telling me completed successfully. didn't.

any ideas?

  $r = get-date   $filename =  ".\logs\" + $r.date.year + "-" + $r.date.month + "-"+ $r.date.day + ".txt"    .\myapp.exe > $filename 

here how able perform in environment minor modifications. code in script below. notice using absolute paths instead of relative powershell launch c:\windows\system32 default path , may not have permission create logs folder , log file in there.

startreport.ps1 script contents:

$r = get-date $filename =  "c:\data\logs\" + $r.date.year + "-" + $r.date.month + "-"+ $r.date.day + ".txt"  & c:\data\myapp.exe > $filename 

notice above using & notation execute exe. can replace command if using &. doing correct. recommend using absolute path.

then in task scheduler have below command:

powershell.exe -file "c:\data\startreport.ps1" 

again using absolute path refer ps1 file. can provide powershell.exe "program/script" , -file "c:\data\startreport.ps1" "add argument" section in action tab of task scheduler.

other considerations

  1. within task scheduler try running highest privilege clicking "run highest privileges" checkbox on general tab of create task dialog. if don't want ensure task scheduler has appropriate permissions create log file.
  2. do ensure logs folder exists.

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -