Roberto Madro R.
asked on
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
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
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?
ASKER
The account by which this task runs under, is an elevated / super user Account.
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
Try setting to 'Run only when user is logged on' and test
ASKER
This is the batch that runs the PS1,
@echo off
start /wait %SystemRoot%\system32\Wind owsPowerSh ell\v1.0\p owershell. exe -ExecutionPolicy Bypass -File "C:\Region\Customer\Custom erActiviti es.ps1"
@echo off
start /wait %SystemRoot%\system32\Wind
Since you kicking off a powershell script no need for cmd batch call
Under actions
Program/script use the following
C:\Windows\System32\Window sPowerShel l\v1.0\pow ershell.ex e
Next
Add arguments (optional) use the following
C:\Region\Customer\Custome rActivitie s.ps1
Next
Start in (optional)
use: C:\Region\Customer<--- not need unless logging is occuring and need to grab current workdir
Under actions
Program/script use the following
C:\Windows\System32\Window
Next
Add arguments (optional) use the following
C:\Region\Customer\Custome
Next
Start in (optional)
use: C:\Region\Customer<--- not need unless logging is occuring and need to grab current workdir
ASKER
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.
See step 4 of implementation in my article
https://www.experts-exchange.com/articles/31687/Windows-Firewall-as-Code.html
https://www.experts-exchange.com/articles/31687/Windows-Firewall-as-Code.html
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
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
ASKER
Shaun; I set it up this way;
Program/scripts: PowerShell.exe
Add arguments (optional): -ExecutionPolicy Bypass -File "%Region%\Customer\Custome rActivitie s.ps1"
The PS1 script directory: C:\Region\Customer\Custome rActivitie s.ps1
To no avail
Program/scripts: PowerShell.exe
Add arguments (optional): -ExecutionPolicy Bypass -File "%Region%\Customer\Custome
The PS1 script directory: C:\Region\Customer\Custome
To no avail
ASKER
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.
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.
correct, the powershell code your running, are there interactive items that the scheduler would not like?
drive mappings can be problematic
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So in fact you didn't change anything but re-set the task action. Doesn't explain anything, sadly.