I have a PowerShell script that I made a task for to run everyday. Is it possible to have the PowerShell window open (and not close after running) so I can make sure it runs without errors? When I schedule with the below command, no window pops up so I can't tell if it every really finished.
powershell -ExecutionPolicy ByPass -File “Q:\myscript.ps1” -NoExit
Additionally, within the script itself, I have a line that opens a text file in Notepad (the transcript of the script from Start-Transcript). When I run the script manually, it opens up Notepad, but the scheduled task did not. Is there a setting to get that to open?
$validationPath = "Q:\transcript.txt"
& Notepad $validationPath
To run interactively you need to select Run only when user is logged on under security options. From the Task Security Context help:
That said, if it is running as a scheduled task, in most cases it would be better to log the output and/or send a email on failure.
For logging you could use
Start-Transcript
, like this:For email notifications you can use
Send-MailMessage