Script Runs in Power Shell but won't run as a BAT file

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

Tamulis,
Welcome to the forum. :wave:t3:

And why don’t you run the PowerShell scripts directly with the task? :man_shrugging:

You know you can run more than just one executable or script with one task, don’t you?

I have read that I could modify the windows task to run the script and not the file. I have no experience with that methodology.

I’m not a developer just an internal resource for my company that gets things done without requesting IT resources.

I researched the method for creating a very functional PS1 process - i certainly could not have accomplished without assistance.

What would be the format of the command in windows scheduler to execute the PS1?

I don’t know what that means!? :thinking: :man_shrugging:

Me neither. :man_shrugging:

Me neither. :wink:

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. :man_shrugging:

You actually used it in your batch file. :point_up: :man_shrugging:

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. :man_shrugging:

Sample action that runs a PS1 file:


This way you don’t need a batch file, which is definitely simpler.

1 Like

Thanks everyone for feedback - I will setup a scheduled task that directly runs Powershell and advise results. I’m optimistic.

1 Like

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.

1 Like

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.