Windows schedule unable to run a ps1 script

I got a PS1 script that's inside a batch job, that PS1 script runs a sql script, I've scheduled a batch job to run that PS1 using Windows server schedule, the scheduler runs and gives the timestamp as having run, when in actuality the the batch (whether it ran or not) doesn't execute the PS1 script, thus not executing the SQL script.

Now, if I was to double click the batch job manually, it runs the PS1 script with no problem, so the problem is something to do with running this particular batch job via the scheduler.

Please advise.
Roberto Madro R.Programmer AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mauro CazabonnetSenior .NET Software EngineerCommented:
Looks like your script run fine interactively. What are the settings for the scheduled task. Are you specifying an account to run the code non-interactively?
Roberto Madro R.Programmer AnalystAuthor Commented:
The account by which this task runs under, is an elevated / super user Account.
Mauro CazabonnetSenior .NET Software EngineerCommented:
Ok without seeing the code. Not all code can run as expected in non-interactive mode
Try setting to 'Run only when user is logged on' and test
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Roberto Madro R.Programmer AnalystAuthor Commented:
This is the batch that runs the PS1,

@echo off
start /wait %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Region\Customer\CustomerActivities.ps1"
Mauro CazabonnetSenior .NET Software EngineerCommented:
Since you kicking off a powershell script no need for cmd batch call

Under actions
Program/script use the following


Add arguments (optional) use the following

Start in (optional)
use: C:\Region\Customer<--- not need unless logging is occuring and need to grab current workdir
Roberto Madro R.Programmer AnalystAuthor Commented:
I just tried your suggestion, changed the job to "Run with the highest privileges" and "Run only when user is logged on", ran it, it gave the impression of doing something, it launched couple of command windows in the background, they stayed open for couple of seconds, the scheduler's  "Next Run Time" & "Last Run Time" changed accordingly, but in actuality nothing happened.
Shaun VermaakTechnical SpecialistCommented:
Mauro CazabonnetSenior .NET Software EngineerCommented:
Ok, I would need to see what the powershell script is doing
task scheduler has limits such as

1. There is no active Shell (explorer.exe)
2. If a process/service tries to display a message box, the task will not complete

You can read further here

Roberto Madro R.Programmer AnalystAuthor Commented:
Shaun; I set it up this way;

Program/scripts: PowerShell.exe
Add arguments (optional): -ExecutionPolicy Bypass -File "%Region%\Customer\CustomerActivities.ps1"

The PS1 script directory:  C:\Region\Customer\CustomerActivities.ps1

To no avail
Roberto Madro R.Programmer AnalystAuthor Commented:

The issue is, if I was to double click the batch file, it runs the PS1 script and generates the data I need, so the only problematic area is that I can't do the same using the scheduler.
Mauro CazabonnetSenior .NET Software EngineerCommented:
correct, the powershell code your running, are there interactive items that the scheduler would not like?
Mauro CazabonnetSenior .NET Software EngineerCommented:
drive mappings can be problematic
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Add -NoExit to the PowerShell call, change the user to your current logged in user, and run the task. You should see the PS console window now. Hopefully with some error messages.
Roberto Madro R.Programmer AnalystAuthor Commented:
Went back to calling the PS1 files from a batch file, what made it work, in Task Scheduler, right-click the task > Actions > Edit > in the "Program Script" browse to your .bat (batch) file, and in the "Start in (optional), add the path to the directory where your batch file lives, but not the batch file itself, just the directory where the batch file is.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
So in fact you didn't change anything but re-set the task action. Doesn't explain anything, sadly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.