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.
Thx
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?
0
Roberto Madro R.Programmer AnalystAuthor Commented:
The account by which this task runs under, is an elevated / super user Account.
0
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
0
Webinar: What were the top threats in Q2 2018?

Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that describes and analyzes the top threat trends impacting companies around the world. Are you ready to learn more about the top threats of Q2 2018? Register for our Sept. 26th webinar to learn more!

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"
0
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

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Next
Add arguments (optional) use the following
C:\Region\Customer\CustomerActivities.ps1

Next
Start in (optional)
use: C:\Region\Customer<--- not need unless logging is occuring and need to grab current workdir
0
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.
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
0
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

https://blogs.technet.microsoft.com/askperf/2015/02/18/help-my-scheduled-task-does-not-run/

M
0
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
0
Roberto Madro R.Programmer AnalystAuthor Commented:
Mauro;

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.
0
Mauro CazabonnetSenior .NET Software EngineerCommented:
correct, the powershell code your running, are there interactive items that the scheduler would not like?
0
Mauro CazabonnetSenior .NET Software EngineerCommented:
drive mappings can be problematic
0
QlemoBatchelor, 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.
0
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.
0

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
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
So in fact you didn't change anything but re-set the task action. Doesn't explain anything, sadly.
0
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
Powershell

From novice to tech pro — start learning today.