I have a powershell script that basically opens a refreshable excel file and creates a copy (new file name). It works beautifully as a PS1 file ran in PowerShell - but when include in a BAT file and scheduling the BAT file via windows task scheduler - I get nothing. Log looks like it executed but it does nothing. No errors in Log.
the bat file is constructed as follows:
@echo off
Powershell.exe -executionpolicy remotesigned -File \xxxx\xxx\xx\RefreshOpenAR.ps1
Powershell.exe -ExecutionPolicy bypass -Command \xxxx\xxx\xx\RefreshOpenAR.ps1
REM pause
I have a couple other tasks that run bat files on a scheduled basis with the same construction - they run fine - so I don’t understand why this doesn’t work. Open to suggestions
That’s fine. I’m maybe on another level but I am actually doing the same. I don’t know everything. If I come around something new I have to do research and learn before I can use it.
You actually used it in your batch file.
How do you set up the task scheduler to execute your batch file? I assume you specify the executable %comspec% or C:\Windows\system32\cmd.exe and for the command line arguments you specify /c completed with the path to your batch file - right?
For PowerShell it’s the same actually. You should run PowerShell.exe /? to learn about the needed command line options and then - instead of adding just one Action for the task you add two.
This really isn’t Powershell specific, but be aware that the account running the scheduled tasks may not have the permissions needed to perform the task in the Powershell script.
That could be another reason why you see that the task has run, but you’re not seeing the expected results.
Good point @laage. @btamulis, if you do run into such issues, adding a Start-Transcript and Stop-Transcript to your PS1 script to capture the output to a file would show you any errors that you can’t see from Task Scheduler.